- Main Page
- Related Pages
- Data Structures
- Files

# usart_example.c

Go to the documentation of this file.

    00001 /*This file is prepared for Doxygen automatic documentation generation.*/
    00086 #include <avr32/io.h>
    00087 #include "compiler.h"
    00088 #include "board.h"
    00089 #include "pm_at32ap7000.h"
    00090 #include "gpio.h"
    00091 #include "usart.h"
    00092
    00093
    00096
    00097 #if BOARD == STK1000
    00098 #  define EXAMPLE_USART               (&AVR32_USART1)
    00099 #  define EXAMPLE_USART_RX_PIN        AVR32_USART1_RXD_0_PIN
    00100 #  define EXAMPLE_USART_RX_FUNCTION   AVR32_USART1_RXD_0_FUNCTION
    00101 #  define EXAMPLE_USART_TX_PIN        AVR32_USART1_TXD_0_PIN
    00102 #  define EXAMPLE_USART_TX_FUNCTION   AVR32_USART1_TXD_0_FUNCTION
    00103 #elif BOARD == NGW100
    00104 #  define EXAMPLE_USART               (&AVR32_USART1)
    00105 #  define EXAMPLE_USART_RX_PIN        AVR32_USART1_RXD_0_PIN
    00106 #  define EXAMPLE_USART_RX_FUNCTION   AVR32_USART1_RXD_0_0_FUNCTION
    00107 #  define EXAMPLE_USART_TX_PIN        AVR32_USART1_TXD_0_PIN
    00108 #  define EXAMPLE_USART_TX_FUNCTION   AVR32_USART1_TXD_0_FUNCTION
    00109 #endif
    00111
    00112
    00116 int main(void)
    00117 {
    00118   static const gpio_map_t USART_GPIO_MAP =
    00119   {
    00120     {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION},
    00121     {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION}
    00122   };
    00123
    00124   // USART options.
    00125   static const usart_options_t USART_OPTIONS =
    00126   {
    00127     .baudrate     = 115200,
    00128     .charlength   = 8,
    00129     .paritytype   = USART_NO_PARITY,
    00130     .stopbits     = USART_1_STOPBIT,
    00131     .channelmode  = USART_NORMAL_CHMODE
    00132   };
    00133
    00134   // Reset PM. Makes sure we get the expected clocking after a soft reset (e.g.: JTAG reset)
    00135   pm_reset();
    00136
    00137   // Assign GPIO to USART.
    00138   gpio_enable_module(USART_GPIO_MAP,
    00139                      sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));
    00140
    00141   // Initialize USART in RS232 mode.
    00142   usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, FOSC0);
    00143
    00144   // Hello world!
    00145   usart_write_line(EXAMPLE_USART, "Hello, this is AT32AP7000 saying hello! (press enter)\n");
    00146
    00147   // Press enter to continue.
    00148   while (usart_get_echo_line(EXAMPLE_USART) == USART_FAILURE);  // Get and echo characters until end of line.
    00149
    00150   usart_write_line(EXAMPLE_USART, "Goodbye.\n");
    00151
    00152   while (TRUE);
    00153 }
    00154