Example of an interrupt-driven USART communication.
Copyright (c) 2009-2018 Microchip Technology Inc. and its subsidiaries.
#include <avr32/io.h>
#include "compiler.h"
#include "board.h"
#include "print_funcs.h"
#include "intc.h"
#include "power_clocks_lib.h"
#include "gpio.h"
#include "usart.h"
#include "conf_example.h"
Functions | |
int | main (void) |
The main function. More... | |
static void | usart_int_handler (void) |
The USART interrupt handler. More... | |
int main | ( | void | ) |
The main function.
It sets up the USART module on EXAMPLE_USART. The terminal settings are 57600 8N1. Then it sets up the interrupt handler and waits for a USART interrupt to trigger.
We have nothing left to do in the main, so we may switch to a device sleep mode: we just need to be sure that the USART module will be still be active in the chosen sleep mode. The sleep mode to use is the FROZEN sleep mode: in this mode the PB clocks are still active (so the USART module which is on the Peripheral Bus will still be
Modules communicating with external circuits should normally be disabled before entering a sleep mode that will stop the module
When the USART interrupt occurs, this will wake the CPU up which will then execute the interrupt handler code then come back to the while(1) loop below to execute the sleep instruction again.
References usart_options_t::baudrate, Disable_global_interrupt, Enable_global_interrupt, EXAMPLE_TARGET_PBACLK_FREQ_HZ, EXAMPLE_USART, EXAMPLE_USART_BAUDRATE, EXAMPLE_USART_IRQ, EXAMPLE_USART_RX_FUNCTION, EXAMPLE_USART_RX_PIN, EXAMPLE_USART_TX_FUNCTION, EXAMPLE_USART_TX_PIN, FOSC0, gpio_enable_module(), INTC_init_interrupts(), INTC_register_interrupt(), OSC0_STARTUP, pcl_configure_clocks(), PCL_OSC0, pcl_switch_to_osc(), print(), SLEEP, USART_1_STOPBIT, usart_init_rs232(), usart_int_handler(), USART_NO_PARITY, and USART_NORMAL_CHMODE.
|
static |
The USART interrupt handler.
References EXAMPLE_USART, usart_read_char(), and usart_write_char().
Referenced by main().