USART Synchronous example for SAM.
Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries.
#include <string.h>
#include "asf.h"
#include "stdio_serial.h"
#include "conf_board.h"
#include "conf_clock.h"
#include "conf_example.h"
Macros | |
#define | ALL_INTERRUPT_MASK 0xffffffff |
All interrupt mask. More... | |
#define | BUFFER_SIZE 2000 |
size of the receive buffer used by the PDC, in bytes. More... | |
#define | FREQ_OPTIONS_NUM 4 |
#define | STATE_READ 0 |
USART is reading. More... | |
#define | STATE_WRITE 1 |
USART is writing. More... | |
#define | STRING_EOL "\r" |
#define | STRING_HEADER |
#define | SYNC_MASTER 1 |
USART synchronous master. More... | |
#define | SYNC_SLAVE 0 |
USART synchronous slave. More... | |
Functions | |
static void | configure_console (void) |
Configure UART for debug message output. More... | |
static void | configure_usart (uint32_t ul_ismaster, uint32_t ul_baudrate) |
Configure USART in synchronous mode. More... | |
static void | display_main_menu (void) |
Display main menu. More... | |
static void | dump_info (char *p_buf, uint32_t ul_size) |
Dump buffer to uart. More... | |
int | main (void) |
Application entry point. More... | |
static uint8_t | transmit_mode_sync (uint8_t *p_buff, uint32_t ulsize) |
transmit data in synchronous mode. More... | |
void | USART0_Handler (void) |
USART IRQ handler. More... | |
Variables | |
uint8_t | g_c_recv_buff [BUFFER_SIZE] = { 0 } |
Buffer for receiving. More... | |
uint8_t | g_uc_freq_idx = 0 |
Present frequency index in list g_ul_freq[]. More... | |
uint8_t | g_uc_state = STATE_WRITE |
State of reading or writing. More... | |
uint8_t | g_uc_transfer_mode = SYNC_MASTER |
Mode for usart, 0 means usart as slave and 1 for master. More... | |
uint32_t | g_ul_freq [FREQ_OPTIONS_NUM] |
Clock freq. More... | |
volatile uint32_t | g_ul_recv_done = false |
Reception is done. More... | |
volatile uint32_t | g_ul_sent_done = false |
Sending is done. More... | |
uint32_t | g_ulcount = 0 |
count number for received data. More... | |
uint8_t * | p_revdata = &g_c_recv_buff[0] |
Pointer to receive buffer base. More... | |
char | tran_buff [BUFFER_SIZE] |
Transmit buffer. More... | |
#define ALL_INTERRUPT_MASK 0xffffffff |
All interrupt mask.
Referenced by configure_usart().
#define BUFFER_SIZE 2000 |
size of the receive buffer used by the PDC, in bytes.
Referenced by main(), and USART0_Handler().
#define FREQ_OPTIONS_NUM 4 |
#define STATE_READ 0 |
USART is reading.
Referenced by main(), and USART0_Handler().
#define STATE_WRITE 1 |
USART is writing.
Referenced by main().
#define STRING_EOL "\r" |
#define STRING_HEADER |
Referenced by main().
#define SYNC_MASTER 1 |
USART synchronous master.
Referenced by main().
#define SYNC_SLAVE 0 |
USART synchronous slave.
Referenced by main().
|
static |
Configure UART for debug message output.
References uart_rs232_options::baudrate, stdio_serial_init(), and sysclk_enable_peripheral_clock().
Referenced by main().
|
static |
Configure USART in synchronous mode.
ul_ismaster | 1 for master, 0 for slave. |
ul_baudrate | Baudrate for synchronous communication. |
References ALL_INTERRUPT_MASK, sam_usart_opt_t::baudrate, sysclk_enable_peripheral_clock(), sysclk_get_peripheral_hz(), usart_disable_interrupt(), usart_enable_rx(), usart_enable_tx(), usart_init_sync_master(), and usart_init_sync_slave().
Referenced by main().
|
static |
Display main menu.
Referenced by main().
|
static |
Dump buffer to uart.
Referenced by main().
int main | ( | void | ) |
Application entry point.
Configure USART in synchronous master/slave mode to start a transmission between two boards.
References board_init(), BUFFER_SIZE, configure_console(), configure_usart(), display_main_menu(), dump_info(), g_c_recv_buff, g_uc_freq_idx, g_uc_state, g_uc_transfer_mode, g_ul_freq, g_ul_recv_done, g_ul_sent_done, g_ulcount, p_revdata, STATE_READ, STATE_WRITE, STRING_HEADER, SYNC_MASTER, SYNC_SLAVE, sysclk_init(), tran_buff, transmit_mode_sync(), and usart_enable_interrupt().
|
static |
transmit data in synchronous mode.
*p_buff | data to be transmitted |
ulsize | size of all data. |
References Assert, g_ul_sent_done, usart_enable_interrupt(), usart_is_tx_empty(), and usart_write().
Referenced by main().
void USART0_Handler | ( | void | ) |
USART IRQ handler.
Interrupt handler for USART. After reception is done, set g_ul_recv_done to true, and if transmission is done, set g_ul_sent_done to true.
References BUFFER_SIZE, g_uc_state, g_ul_recv_done, g_ulcount, p_revdata, STATE_READ, usart_disable_interrupt(), usart_get_status(), and usart_read().
uint8_t g_c_recv_buff[BUFFER_SIZE] = { 0 } |
Buffer for receiving.
Referenced by main().
uint8_t g_uc_freq_idx = 0 |
Present frequency index in list g_ul_freq[].
Referenced by main().
uint8_t g_uc_state = STATE_WRITE |
State of reading or writing.
uint8_t g_uc_transfer_mode = SYNC_MASTER |
Mode for usart, 0 means usart as slave and 1 for master.
Referenced by main().
uint32_t g_ul_freq[FREQ_OPTIONS_NUM] |
volatile uint32_t g_ul_recv_done = false |
Reception is done.
Referenced by main(), and USART0_Handler().
volatile uint32_t g_ul_sent_done = false |
Sending is done.
Referenced by main(), and transmit_mode_sync().
uint32_t g_ulcount = 0 |
count number for received data.
Referenced by main(), USART0_Handler(), and USART_Handler().
uint8_t* p_revdata = &g_c_recv_buff[0] |
Pointer to receive buffer base.
Referenced by main(), USART0_Handler(), and USART_Handler().
char tran_buff[BUFFER_SIZE] |
Transmit buffer.
Referenced by main().