Definition in file usart_example.c.
#include <avr32/io.h>
#include "compiler.h"
#include "board.h"
#include "power_clocks_lib.h"
#include "gpio.h"
#include "usart.h"
Go to the source code of this file.
Defines | |
USART Settings | |
#define | EXAMPLE_PDCA_CLOCK_HSB AVR32_PDCA_CLK_HSB |
#define | EXAMPLE_PDCA_CLOCK_PB AVR32_PDCA_CLK_PBA |
#define | EXAMPLE_TARGET_DFLL_FREQ_HZ 96000000 |
#define | EXAMPLE_TARGET_MCUCLK_FREQ_HZ 12000000 |
#define | EXAMPLE_TARGET_PBACLK_FREQ_HZ 12000000 |
#define | EXAMPLE_TARGET_PBACLK_FREQ_HZ FOSC0 |
#define | EXAMPLE_USART (&AVR32_USART3) |
#define | EXAMPLE_USART_CLOCK_MASK AVR32_USART3_CLK_PBA |
#define | EXAMPLE_USART_RX_FUNCTION AVR32_USART3_RXD_0_0_FUNCTION |
#define | EXAMPLE_USART_RX_PIN AVR32_USART3_RXD_0_0_PIN |
#define | EXAMPLE_USART_TX_FUNCTION AVR32_USART3_TXD_0_0_FUNCTION |
#define | EXAMPLE_USART_TX_PIN AVR32_USART3_TXD_0_0_PIN |
Functions | |
int | main (void) |
This is an example demonstrating the USART RS232 TX and RX functionalities using the USART driver. | |
Variables | |
Parameters to pcl_configure_clocks(). | |
static scif_gclk_opt_t | gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, OFF } |
static pcl_freq_param_t | pcl_dfll_freq_param |
#define EXAMPLE_PDCA_CLOCK_HSB AVR32_PDCA_CLK_HSB |
#define EXAMPLE_PDCA_CLOCK_PB AVR32_PDCA_CLK_PBA |
#define EXAMPLE_TARGET_DFLL_FREQ_HZ 96000000 |
Definition at line 173 of file usart_example.c.
#define EXAMPLE_TARGET_MCUCLK_FREQ_HZ 12000000 |
Definition at line 174 of file usart_example.c.
#define EXAMPLE_TARGET_PBACLK_FREQ_HZ 12000000 |
Definition at line 176 of file usart_example.c.
#define EXAMPLE_TARGET_PBACLK_FREQ_HZ FOSC0 |
#define EXAMPLE_USART (&AVR32_USART3) |
#define EXAMPLE_USART_CLOCK_MASK AVR32_USART3_CLK_PBA |
#define EXAMPLE_USART_RX_FUNCTION AVR32_USART3_RXD_0_0_FUNCTION |
#define EXAMPLE_USART_RX_PIN AVR32_USART3_RXD_0_0_PIN |
#define EXAMPLE_USART_TX_FUNCTION AVR32_USART3_TXD_0_0_FUNCTION |
#define EXAMPLE_USART_TX_PIN AVR32_USART3_TXD_0_0_PIN |
int main | ( | void | ) |
This is an example demonstrating the USART RS232 TX and RX functionalities using the USART driver.
Definition at line 212 of file usart_example.c.
References EXAMPLE_PDCA_CLOCK_HSB, EXAMPLE_PDCA_CLOCK_PB, EXAMPLE_TARGET_PBACLK_FREQ_HZ, EXAMPLE_USART, EXAMPLE_USART_CLOCK_MASK, EXAMPLE_USART_RX_FUNCTION, EXAMPLE_USART_RX_PIN, EXAMPLE_USART_TX_FUNCTION, EXAMPLE_USART_TX_PIN, pcl_dfll_freq_param, USART_1_STOPBIT, USART_FAILURE, usart_get_echo_line(), usart_init_rs232(), USART_NO_PARITY, USART_NORMAL_CHMODE, usart_tx_empty(), and usart_write_line().
00213 { 00214 static const gpio_map_t USART_GPIO_MAP = 00215 { 00216 {EXAMPLE_USART_RX_PIN, EXAMPLE_USART_RX_FUNCTION}, 00217 {EXAMPLE_USART_TX_PIN, EXAMPLE_USART_TX_FUNCTION} 00218 }; 00219 00220 // USART options. 00221 static const usart_options_t USART_OPTIONS = 00222 { 00223 .baudrate = 57600, 00224 .charlength = 8, 00225 .paritytype = USART_NO_PARITY, 00226 .stopbits = USART_1_STOPBIT, 00227 .channelmode = USART_NORMAL_CHMODE 00228 }; 00229 00230 00231 #if BOARD == UC3L_EK 00232 // Note: on the AT32UC3L-EK board, there is no crystal/external clock connected 00233 // to the OSC0 pinout XIN0/XOUT0. We shall then program the DFLL and switch the 00234 // main clock source to the DFLL. 00235 pcl_configure_clocks(&pcl_dfll_freq_param); 00236 // Note: since it is dynamically computing the appropriate field values of the 00237 // configuration registers from the parameters structure, this function is not 00238 // optimal in terms of code size. For a code size optimal solution, it is better 00239 // to create a new function from pcl_configure_clocks_dfll0() and modify it 00240 // to use preprocessor computation from pre-defined target frequencies. 00241 #else 00242 // Configure Osc0 in crystal mode (i.e. use of an external crystal source, with 00243 // frequency FOSC0) with an appropriate startup time then switch the main clock 00244 // source to Osc0. 00245 pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP); 00246 #endif 00247 00248 // Assign GPIO to USART. 00249 gpio_enable_module(USART_GPIO_MAP, 00250 sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0])); 00251 00252 // Initialize USART in RS232 mode. 00253 usart_init_rs232(EXAMPLE_USART, &USART_OPTIONS, EXAMPLE_TARGET_PBACLK_FREQ_HZ); 00254 00255 // Hello world! 00256 usart_write_line(EXAMPLE_USART, "Hello, this is AT32UC3 saying hello! (press enter)\n"); 00257 00258 // Press enter to continue. 00259 while (usart_get_echo_line(EXAMPLE_USART) == USART_FAILURE); // Get and echo characters until end of line. 00260 00261 usart_write_line(EXAMPLE_USART, "Goodbye.\n"); 00262 00263 //*** Sleep mode 00264 // This program won't be doing anything else from now on, so it might as well 00265 // sleep. 00266 // Modules communicating with external circuits should normally be disabled 00267 // before entering a sleep mode that will stop the module operation. 00268 // Make sure the USART dumps the last message completely before turning it off. 00269 while(!usart_tx_empty(EXAMPLE_USART)); 00270 pcl_disable_module(EXAMPLE_USART_CLOCK_MASK); 00271 00272 // Since we're going into a sleep mode deeper than IDLE, all HSB masters must 00273 // be stopped before entering the sleep mode. 00274 pcl_disable_module(EXAMPLE_PDCA_CLOCK_HSB); 00275 pcl_disable_module(EXAMPLE_PDCA_CLOCK_PB); 00276 00277 // If there is a chance that any PB write operations are incomplete, the CPU 00278 // should perform a read operation from any register on the PB bus before 00279 // executing the sleep instruction. 00280 AVR32_INTC.ipr[0]; // Dummy read 00281 00282 // Go to STATIC sleep mode. 00283 SLEEP(AVR32_PM_SMODE_STATIC); 00284 00285 while (TRUE); 00286 }
scif_gclk_opt_t gc_dfllif_ref_opt = { SCIF_GCCTRL_SLOWCLOCK, 0, OFF } [static] |
Definition at line 196 of file usart_example.c.
pcl_freq_param_t pcl_dfll_freq_param [static] |
Initial value:
{ .main_clk_src = PCL_MC_DFLL0, .cpu_f = EXAMPLE_TARGET_MCUCLK_FREQ_HZ, .pba_f = EXAMPLE_TARGET_PBACLK_FREQ_HZ, .pbb_f = EXAMPLE_TARGET_PBACLK_FREQ_HZ, .dfll_f = EXAMPLE_TARGET_DFLL_FREQ_HZ, .pextra_params = &gc_dfllif_ref_opt }
Definition at line 197 of file usart_example.c.
Referenced by main().