---conf_board.h
#define CONF_BOARD_ENABLE_USARTD0
#define USART_RX_Vect USARTD0_RXC_vect
---conf_sleepmgr.h
#define CONFIG_SLEEPMGR_ENABLE
---
#define USART_SERIAL_EXAMPLE &USARTD0
#define USART_SERIAL_EXAMPLE_BAUDRATE 115200
#define USART_SERIAL_CHAR_LENGTH USART_CHSIZE_8BIT_gc
#define USART_SERIAL_PARITY USART_PMODE_DISABLED_gc
#define USART_SERIAL_STOP_BIT false
---main
#include <conf_usart_example.h>
#include <asf.h>
#define LED0_GPIO IOPORT_CREATE_PIN(PORTC, 0)
#define LED1_GPIO IOPORT_CREATE_PIN(PORTC, 1)
#define LED2_GPIO IOPORT_CREATE_PIN(PORTC, 2)
#define LED0 LED0_GPIO
ISR(USART_RX_Vect)
{
usart_putchar(USART_SERIAL_EXAMPLE,
usart_getchar(USART_SERIAL_EXAMPLE));
while (!usart_tx_is_complete(USART_SERIAL_EXAMPLE)) {
}
usart_clear_tx_complete(USART_SERIAL_EXAMPLE);
}
int main(void)
{
uint8_t tx_buf[] = "\n\rHello AVR world ! : ";
uint8_t tx_length = 22;
uint8_t received_byte;
uint8_t i;
board_init();
sysclk_init();
pmic_init();
cpu_irq_enable();
sleepmgr_init();
sleepmgr_lock_mode(SLEEPMGR_IDLE);//SLEEPMGR_STDBY);
ioport_configure_pin(LED0_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
ioport_configure_pin(LED1_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
ioport_configure_pin(LED2_GPIO, IOPORT_DIR_OUTPUT | IOPORT_INIT_HIGH);
gpio_set_pin_high(LED0);
// USART options.
static usart_rs232_options_t USART_SERIAL_OPTIONS = {
.baudrate = USART_SERIAL_EXAMPLE_BAUDRATE,
.charlength = USART_SERIAL_CHAR_LENGTH,
.paritytype = USART_SERIAL_PARITY,
.stopbits = USART_SERIAL_STOP_BIT
};
// Initialize usart driver in RS232 mode
usart_init_rs232(USART_SERIAL_EXAMPLE, &USART_SERIAL_OPTIONS);
usart_set_rx_interrupt_level(USART_SERIAL_EXAMPLE, USART_INT_LVL_LO);
for (i = 0; i < sizeof(tx_buf); i++) {
usart_putchar(USART_SERIAL_EXAMPLE, tx_buf[i]);
while (!usart_tx_is_complete(USART_SERIAL_EXAMPLE)) {
}
usart_clear_tx_complete(USART_SERIAL_EXAMPLE);
}
while (true) {
sleepmgr_enter_sleep();
gpio_toggle_pin(LED0);
}
}