USART - Synchronous/Asynchronous Serial

Description

Universal Synchronous/Asynchronous Receiver/Transmitter Peripheral API.

The Universal Synchronous/Asynchronous Receiver/Transmitter (USART) is a very flexible serial I/O module. It supports full duplex asynchronous UART communication as well as RS-485, SPI, MicroWire, and 3-wire. It can also interface with ISO7816 Smart-Cards, and IrDA devices.

The USART has a wide selection of operating modes, frame formats, and baud rates. All features are supported through the API of this module.

Triple buffering and DMA support makes high data-rates possible with minimal CPU intervention. It is possible to transmit and receive large frames while the MCU remains in EM1 Sleep.

This module does not support DMA configuration. The UARTDRV and SPIDRV drivers provide full support for DMA and more.

The following steps are necessary for basic operation:

Clock enable:

#if !defined(_SILICON_LABS_32B_SERIES_2)
/* USART is a HFPERCLK peripheral. Enable HFPERCLK domain and USART0.
* We also need to enable the clock for GPIO to configure pins. */
#endif

To initialize the USART for asynchronous operation (e.g., UART):

/* Initialize with default settings and then update fields according to application requirements. */
initAsync. baudrate = 38400;
USART_InitAsync (USART0, &initAsync);

To initialize the USART for synchronous operation (e.g., SPI):

/* Initialize with default settings and then update fields according to application requirements. */
/* Operate as SPI master */
initSync. master = true ;
/* Clock idle low, sample on falling edge. */
USART_InitSync (USART0, &initSync);

After pins are assigned for the application/board, enable pins at the desired location. Available locations can be obtained from the Pin Definitions section in the data sheet.

/* Enable I/O and set location */
USART0->ROUTE = USART_ROUTE_RXPEN | USART_ROUTE_TXPEN | USER_LOCATION;
/* Also enable CS and CLK pins if the USART is configured for synchronous mode.
* Set GPIO mode. */
if (USART0->CTRL & USART_CTRL_SYNC) {
USART0->ROUTE |= USART_ROUTE_CSPEN | USART_ROUTE_CLKPEN;
GPIO_PinModeSet (( GPIO_Port_TypeDef )AF_USART0_TX_PORT(USER_LOCATION), AF_USART0_TX_PIN(USER_LOCATION), gpioModePushPull , 0);
GPIO_PinModeSet (( GPIO_Port_TypeDef )AF_USART0_RX_PORT(USER_LOCATION), AF_USART0_RX_PIN(USER_LOCATION), gpioModeInput , 0);
GPIO_PinModeSet (( GPIO_Port_TypeDef )AF_USART0_CS_PORT(USER_LOCATION), AF_USART0_CS_PIN(USER_LOCATION), gpioModePushPull , 0);
GPIO_PinModeSet (( GPIO_Port_TypeDef )AF_USART0_CLK_PORT(USER_LOCATION), AF_USART0_CLK_PIN(USER_LOCATION), gpioModePushPull , 0);
} else {
/* To avoid false start, configure TX pin as initial high */
GPIO_PinModeSet (( GPIO_Port_TypeDef )AF_USART0_TX_PORT(USER_LOCATION), AF_USART0_TX_PIN(USER_LOCATION), gpioModePushPull , 1);
GPIO_PinModeSet (( GPIO_Port_TypeDef )AF_USART0_RX_PORT(USER_LOCATION), AF_USART0_RX_PIN(USER_LOCATION), gpioModeInput , 0);
/* Don't enable CTS/RTS hardware flow control pins in this example. */
}
Note
UART hardware flow control is not directly supported in hardware on _SILICON_LABS_32B_SERIES_0 parts.
UARTDRV supports all types of UART flow control. Software assisted hardware flow control is available for parts without true UART hardware flow control.

Data Structures

struct USART_InitAsync_TypeDef
Asynchronous mode initialization structure.
struct USART_PrsTriggerInit_TypeDef
USART PRS trigger enable.
struct USART_InitSync_TypeDef
Synchronous mode initialization structure.
struct USART_InitIrDA_TypeDef
IrDA mode initialization structure.
struct USART_InitI2s_TypeDef
I2S mode initialization structure.

Functions

void USART_BaudrateAsyncSet (USART_TypeDef *usart, uint32_t refFreq, uint32_t baudrate, USART_OVS_TypeDef ovs)
Configure USART/UART operating in asynchronous mode to use a given baudrate (or as close as possible to a specified baudrate).
uint32_t USART_BaudrateCalc (uint32_t refFreq, uint32_t clkdiv, bool syncmode, USART_OVS_TypeDef ovs)