usart_example.c File Reference


Detailed Description

Example on usage of the AVR32 USART device library.

This file contains an example on how to use the AVR32 USART driver. It initializes the USART and puts out a string. See the documentation or comments within the file for settings and more info

Author:
Atmel Corporation: http://www.atmel.com
Support email: avr32@atmel.com
$Name$
Revision
67
$RCSfile$
Date
2006-05-10 15:00:07 +0200 (Wed, 10 May 2006)

Definition in file usart_example.c.

#include "usart.h"

Include dependency graph for usart_example.c:

Go to the source code of this file.

Defines

#define FAILURE   -1;
#define SUCCESS   0;

Typedefs

typedef unsigned char avr32_piomap_t [][2]

Functions

int main (void)
 Sets up the USART and print's a string.
int pio_enable_module (avr32_piomap_t piomap, unsigned int size)
 Set the pins under module control.
void print (volatile struct avr32_usart_t *usart, char *str)
 Print a string of characters to an usart.


Define Documentation

#define FAILURE   -1;

Definition at line 62 of file usart_example.c.

Referenced by pio_enable_module().

#define SUCCESS   0;

Definition at line 61 of file usart_example.c.

Referenced by main().


Typedef Documentation

typedef unsigned char avr32_piomap_t[][2]

Definition at line 64 of file usart_example.c.


Function Documentation

int main ( void   ) 

Sets up the USART and print's a string.

Parameters:
 
Returns:
;

Definition at line 96 of file usart_example.c.

References usart_options_t::baudrate, usart_options_t::channelmode, usart_options_t::charlength, usart_options_t::paritytype, pio_enable_module(), print(), usart_options_t::stopbits, SUCCESS, USART_1_STOPBIT, usart_init_rs232(), USART_NO_PARITY, and USART_NORMAL_CHMODE.

00097 {
00098   int cpu_hz = 20000000;
00099   struct usart_options_t opt;
00100 
00101   volatile struct avr32_usart_t *usart = &AVR32_USART1;
00102 
00103   avr32_piomap_t usart_piomap = {                                  \
00104     {AVR32_USART1_RXD_0_PIN, AVR32_USART1_RXD_0_FUNCTION}, \
00105     {AVR32_USART1_TXD_0_PIN, AVR32_USART1_TXD_0_FUNCTION}   \
00106   };
00107 
00108   // Set options for the USART
00109   opt.baudrate = 115200;
00110   opt.charlength = 8;
00111   opt.paritytype = USART_NO_PARITY;
00112   opt.stopbits = USART_1_STOPBIT;
00113   opt.channelmode = USART_NORMAL_CHMODE;
00114 
00115   // Initialize it in RS232 mode
00116   usart_init_rs232(usart, &opt, cpu_hz);
00117 
00118   // Setup pio for USART
00119   pio_enable_module(usart_piomap, 2);
00120 
00121   print(usart, "This is AVR32 saying hello from the STK1000!\n");
00122 
00123   return SUCCESS;
00124 }

Here is the call graph for this function:

int pio_enable_module ( avr32_piomap_t  piomap,
unsigned int  size 
)

Set the pins under module control.

Parameters:
piomap a map describing how the setup of the PIO
size number of elements in the map
Returns:
Status or error code
Return values:
SUCCESS on success
FAILURE on bad values in piomap

Definition at line 150 of file usart_example.c.

References FAILURE.

Referenced by main().

00151 {
00152   int i;
00153   volatile struct avr32_pio_t *pio;
00154 
00155   /* get the base address for the port */
00156   switch (**piomap/32) {
00157 
00158   case 0:
00159     pio = &AVR32_PIOA;
00160     break;
00161   case 1:
00162     pio = &AVR32_PIOB;
00163     break;
00164   case 2:
00165     pio = &AVR32_PIOC;
00166     break;
00167   case 3:
00168     pio = &AVR32_PIOD;
00169     break;
00170   case 4:
00171     pio = &AVR32_PIOE;
00172     break;
00173   default :
00174     return FAILURE;
00175 
00176   }
00177 
00178   for(i=0; i<size; i++){
00179 
00180     pio->pdr |= ( 1<<( (**piomap) % 32) );
00181     pio->pudr |= ( 1<<( (**piomap) % 32) );
00182 
00183     switch( *(*piomap+1) ){    
00184     case 0:
00185       pio->asr |= ( 1<<( (**piomap) % 32) );
00186       break;
00187     case 1:
00188       pio->bsr |= ( 1<<( (**piomap) % 32) );
00189       break;
00190     default:
00191       return FAILURE;
00192     }
00193 
00194     ++piomap;
00195 
00196   }
00197   
00198   return SUCCESS;
00199 }

void print ( volatile struct avr32_usart_t *  usart,
char *  str 
)

Print a string of characters to an usart.

Parameters:
*usart The usart to write to
*str The string of characters
Returns:
;

Definition at line 134 of file usart_example.c.

References usart_putchar().

Referenced by main().

00135 {
00136         while (*str != '\0')
00137                 usart_putchar(usart, *str++);
00138 }

Here is the call graph for this function:


Generated on Thu May 10 14:17:57 2007 for AVR321000 Communication with the AVR32 USART by  doxygen 1.5.1