USARTEMLIB

Detailed 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->ROUTELOC0 = (USART0->ROUTELOC0
| (USER_TX_LOCATION << _USART_ROUTELOC0_TXLOC_SHIFT)
| (USER_RX_LOCATION << _USART_ROUTELOC0_RXLOC_SHIFT);
/* Also enable CS and CLK pins if the USART is configured for synchronous mode.
* Set GPIO mode. */
if (USART0->CTRL & USART_CTRL_SYNC) {
USART0->ROUTELOC0 = (USART0->ROUTELOC0
| (USER_CS_LOCATION << _USART_ROUTELOC0_TXLOC_SHIFT)
| (USER_CLK_LOCATION << _USART_ROUTELOC0_RXLOC_SHIFT);
} else {
/* To avoid false start, configure TX pin as initial high */
/* Don't enable CTS/RTS hardware flow control pins in this example. Automatic hardware flow control is available and can be
* enabled by setting USART_ROUTEPEN_RTSPEN and USART_ROUTEPEN_CTSPEN, and enable GPIO for the RTS/CTS pins. */
}
Note
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
 
struct  USART_InitI2s_TypeDef
 
struct  USART_InitIrDA_TypeDef
 
struct  USART_InitSync_TypeDef
 
struct  USART_PrsTriggerInit_TypeDef
 

Macros

#define USART_INITASYNC_DEFAULT
 
#define USART_INITI2S_DEFAULT
 
#define USART_INITIRDA_DEFAULT
 
#define USART_INITPRSTRIGGER_DEFAULT
 
#define USART_INITSYNC_DEFAULT
 
#define usartIrDAPrsCh0   0U
 
#define usartIrDAPrsCh1   1U
 
#define usartIrDAPrsCh2   2U
 
#define usartIrDAPrsCh3   3U
 
#define usartIrDAPrsCh4   4U
 
#define usartIrDAPrsCh5   5U
 
#define usartIrDAPrsCh6   6U
 
#define usartIrDAPrsCh7   7U
 
#define usartPrsRxCh0   0U
 
#define usartPrsRxCh1   1U
 
#define usartPrsRxCh10   10U
 
#define usartPrsRxCh11   11U
 
#define usartPrsRxCh2   2U
 
#define usartPrsRxCh3   3U
 
#define usartPrsRxCh4   4U
 
#define usartPrsRxCh5   5U
 
#define usartPrsRxCh6   6U
 
#define usartPrsRxCh7   7U
 
#define usartPrsRxCh8   8U
 
#define usartPrsRxCh9   9U
 
#define usartPrsTriggerCh0   0U
 
#define usartPrsTriggerCh1   1U
 
#define usartPrsTriggerCh2   2U
 
#define usartPrsTriggerCh3   3U
 
#define usartPrsTriggerCh4   4U
 
#define usartPrsTriggerCh5   5U
 
#define usartPrsTriggerCh6   6U
 
#define usartPrsTriggerCh7   7U
 

Typedefs

typedef uint8_t USART_PRS_Channel_t
 

Enumerations

enum  USART_ClockMode_TypeDef {
  usartClockMode0 = USART_CTRL_CLKPOL_IDLELOW | USART_CTRL_CLKPHA_SAMPLELEADING,
  usartClockMode1 = USART_CTRL_CLKPOL_IDLELOW | USART_CTRL_CLKPHA_SAMPLETRAILING,
  usartClockMode2 = USART_CTRL_CLKPOL_IDLEHIGH | USART_CTRL_CLKPHA_SAMPLELEADING,
  usartClockMode3 = USART_CTRL_CLKPOL_IDLEHIGH | USART_CTRL_CLKPHA_SAMPLETRAILING
}
 
enum  USART_Databits_TypeDef {
  usartDatabits4 = USART_FRAME_DATABITS_FOUR,
  usartDatabits5 = USART_FRAME_DATABITS_FIVE,
  usartDatabits6 = USART_FRAME_DATABITS_SIX,
  usartDatabits7 = USART_FRAME_DATABITS_SEVEN,
  usartDatabits8 = USART_FRAME_DATABITS_EIGHT,
  usartDatabits9 = USART_FRAME_DATABITS_NINE,
  usartDatabits10 = USART_FRAME_DATABITS_TEN,
  usartDatabits11 = USART_FRAME_DATABITS_ELEVEN,
  usartDatabits12 = USART_FRAME_DATABITS_TWELVE,
  usartDatabits13 = USART_FRAME_DATABITS_THIRTEEN,
  usartDatabits14 = USART_FRAME_DATABITS_FOURTEEN,
  usartDatabits15 = USART_FRAME_DATABITS_FIFTEEN,
  usartDatabits16 = USART_FRAME_DATABITS_SIXTEEN
}
 
enum  USART_Enable_TypeDef {
  usartDisable = 0x0,
  usartEnableRx = USART_CMD_RXEN,
  usartEnableTx = USART_CMD_TXEN,
  usartEnable = (USART_CMD_RXEN | USART_CMD_TXEN)
}
 
enum  USART_HwFlowControl_TypeDef {
  usartHwFlowControlNone = 0,
  usartHwFlowControlCts = USART_ROUTEPEN_CTSPEN,
  usartHwFlowControlRts = USART_ROUTEPEN_RTSPEN,
  usartHwFlowControlCtsAndRts = USART_ROUTEPEN_CTSPEN | USART_ROUTEPEN_RTSPEN
}
 
enum  USART_I2sFormat_TypeDef {
  usartI2sFormatW32D32 = USART_I2SCTRL_FORMAT_W32D32,
  usartI2sFormatW32D24M = USART_I2SCTRL_FORMAT_W32D24M,
  usartI2sFormatW32D24 = USART_I2SCTRL_FORMAT_W32D24,
  usartI2sFormatW32D16 = USART_I2SCTRL_FORMAT_W32D16,
  usartI2sFormatW32D8 = USART_I2SCTRL_FORMAT_W32D8,
  usartI2sFormatW16D16 = USART_I2SCTRL_FORMAT_W16D16,
  usartI2sFormatW16D8 = USART_I2SCTRL_FORMAT_W16D8,
  usartI2sFormatW8D8 = USART_I2SCTRL_FORMAT_W8D8
}
 
enum  USART_I2sJustify_TypeDef {
  usartI2sJustifyLeft = USART_I2SCTRL_JUSTIFY_LEFT,
  usartI2sJustifyRight = USART_I2SCTRL_JUSTIFY_RIGHT
}
 
enum  USART_IrDAPw_Typedef {
  usartIrDAPwONE = USART_IRCTRL_IRPW_ONE,
  usartIrDAPwTWO = USART_IRCTRL_IRPW_TWO,
  usartIrDAPwTHREE = USART_IRCTRL_IRPW_THREE,
  usartIrDAPwFOUR = USART_IRCTRL_IRPW_FOUR
}
 
enum  USART_OVS_TypeDef {
  usartOVS16 = USART_CTRL_OVS_X16,
  usartOVS8 = USART_CTRL_OVS_X8,
  usartOVS6 = USART_CTRL_OVS_X6,
  usartOVS4 = USART_CTRL_OVS_X4
}
 
enum  USART_Parity_TypeDef {
  usartNoParity = USART_FRAME_PARITY_NONE,
  usartEvenParity = USART_FRAME_PARITY_EVEN,
  usartOddParity = USART_FRAME_PARITY_ODD
}
 
enum  USART_Stopbits_TypeDef {
  usartStopbits0p5 = USART_FRAME_STOPBITS_HALF,
  usartStopbits1 = USART_FRAME_STOPBITS_ONE,
  usartStopbits1p5 = USART_FRAME_STOPBITS_ONEANDAHALF,
  usartStopbits2 = USART_FRAME_STOPBITS_TWO
}
 

Functions

static void prsIrInput (USART_TypeDef *usart, USART_PRS_Channel_t ch)
 Configure a PRS channel as USART Ir input.
 
static void prsRxInput (USART_TypeDef *usart, USART_PRS_Channel_t ch)
 Configure a PRS channel as USART Rx input.
 
static void prsTriggerInput (USART_TypeDef *usart, USART_PRS_Channel_t ch)
 Configure a PRS channel as USART Trigger input.
 
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)
 Calculate baudrate for USART/UART given reference frequency, clock division, and oversampling rate (if async mode).
 
uint32_t USART_BaudrateGet (USART_TypeDef *usart)
 Get the current baudrate for USART/UART.
 
void USART_BaudrateSyncSet (USART_TypeDef *usart, uint32_t refFreq, uint32_t baudrate)
 Configure the USART operating in synchronous mode to use a given baudrate (or as close as possible to a specified baudrate).
 
void USART_Enable (USART_TypeDef *usart, USART_Enable_TypeDef enable)
 Enable/disable USART/UART receiver and/or transmitter.
 
void USART_InitAsync (USART_TypeDef *usart, const USART_InitAsync_TypeDef *init)
 Initialize USART/UART for normal asynchronous mode.
 
void USART_InitI2s (USART_TypeDef *usart, USART_InitI2s_TypeDef *init)
 Initialize USART for I2S mode.
 
__STATIC_INLINE void USART_InitIrDA (const USART_InitIrDA_TypeDef *init)
 Initialization DEFAULT_IRDA_USART for asynchronous IrDA mode.
 
void USART_InitPrsTrigger (USART_TypeDef *usart, const USART_PrsTriggerInit_TypeDef *init)
 Initialize the automatic transmissions using PRS channel as a trigger.
 
void USART_InitSync (USART_TypeDef *usart, const USART_InitSync_TypeDef *init)
 Initialize USART for synchronous mode.
 
__STATIC_INLINE void USART_IntClear (USART_TypeDef *usart, uint32_t flags)
 Clear one or more pending USART interrupts.
 
__STATIC_INLINE void USART_IntDisable (USART_TypeDef *usart, uint32_t flags)
 Disable one or more USART interrupts.
 
__STATIC_INLINE void USART_IntEnable (USART_TypeDef *usart, uint32_t flags)
 Enable one or more USART interrupts.
 
__STATIC_INLINE uint32_t USART_IntGet (USART_TypeDef *usart)
 Get pending USART interrupt flags.
 
__STATIC_INLINE uint32_t USART_IntGetEnabled (USART_TypeDef *usart)
 Get enabled and pending USART interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.
 
__STATIC_INLINE void USART_IntSet (USART_TypeDef *usart, uint32_t flags)
 Set one or more pending USART interrupts from SW.
 
void USART_Reset (USART_TypeDef *usart)
 Reset USART/UART to the same state that it was in after a hardware reset.
 
uint8_t USART_Rx (USART_TypeDef *usart)
 Receive one 4-8 bit frame, (or part of 10-16 bit frame).
 
__STATIC_INLINE uint8_t USART_RxDataGet (USART_TypeDef *usart)
 Receive one 4-8 bit frame, (or part of 10-16 bit frame).
 
__STATIC_INLINE uint16_t USART_RxDataXGet (USART_TypeDef *usart)
 Receive one 4-9 bit frame, (or part of 10-16 bit frame) with extended information.
 
uint16_t USART_RxDouble (USART_TypeDef *usart)
 Receive two 4-8 bit frames or one 10-16 bit frame.
 
uint32_t USART_RxDoubleExt (USART_TypeDef *usart)
 Receive two 4-9 bit frames, or one 10-16 bit frame with extended information.
 
__STATIC_INLINE uint16_t USART_RxDoubleGet (USART_TypeDef *usart)
 Receive two 4-8 bit frames, or one 10-16 bit frame.
 
__STATIC_INLINE uint32_t USART_RxDoubleXGet (USART_TypeDef *usart)
 Receive two 4-9 bit frames, or one 10-16 bit frame with extended information.
 
uint16_t USART_RxExt (USART_TypeDef *usart)
 Receive one 4-9 bit frame (or part of 10-16 bit frame) with extended information.
 
uint8_t USART_SpiTransfer (USART_TypeDef *usart, uint8_t data)
 Perform one 8 bit frame SPI transfer.
 
__STATIC_INLINE uint32_t USART_StatusGet (USART_TypeDef *usart)
 Get USART STATUS register.
 
void USART_Tx (USART_TypeDef *usart, uint8_t data)
 Transmit one 4-9 bit frame.
 
void USART_TxDouble (USART_TypeDef *usart, uint16_t data)
 Transmit two 4-9 bit frames or one 10-16 bit frame.
 
void USART_TxDoubleExt (USART_TypeDef *usart, uint32_t data)
 Transmit two 4-9 bit frames or one 10-16 bit frame with extended control.
 
void USART_TxExt (USART_TypeDef *usart, uint16_t data)
 Transmit one 4-9 bit frame with extended control.
 
void USARTn_InitIrDA (USART_TypeDef *usart, const USART_InitIrDA_TypeDef *init)
 Initialize USART for asynchronous IrDA mode.
 

Macro Definition Documentation

#define USART_INITASYNC_DEFAULT
Value:
{ \
usartEnable, /* Enable RX/TX when initialization is complete. */ \
0, /* Use current configured reference clock for configuring baud rate. */ \
115200, /* 115200 bits/s. */ \
usartOVS16, /* 16x oversampling. */ \
usartDatabits8, /* 8 data bits. */ \
usartNoParity, /* No parity. */ \
usartStopbits1, /* 1 stop bit. */ \
false, /* Do not disable majority vote. */ \
false, /* Not USART PRS input mode. */ \
0, /* PRS channel 0. */ \
false, /* Auto CS functionality enable/disable switch */ \
0, /* Auto CS Hold cycles */ \
0, /* Auto CS Setup cycles */ \
usartHwFlowControlNone /* No HW flow control */ \
}

Default configuration for USART asynchronous initialization structure.

Definition at line 381 of file em_usart.h.

Referenced by BSP_BccInit(), RETARGET_SerialInit(), and UARTDRV_InitUart().

#define USART_INITI2S_DEFAULT
Value:
{ \
{ \
usartEnableTx, /* Enable TX when init completed. */ \
0, /* Use current configured reference clock for configuring baudrate. */ \
1000000, /* Baudrate 1M bits/s. */ \
usartDatabits16, /* 16 databits. */ \
true, /* Operate as I2S master. */ \
true, /* Most significant bit first. */ \
usartClockMode0, /* Clock idle low, sample on rising edge. */ \
false, /* Don't enable USARTRx via PRS. */ \
usartPrsRxCh0, /* PRS channel selection (dummy). */ \
false, /* Disable AUTOTX mode. */ \
false, /* No AUTOCS mode */ \
0, /* Auto CS Hold cycles */ \
0 /* Auto CS Setup cycles */ \
}, \
usartI2sFormatW16D16, /* 16-bit word, 16-bit data */ \
true, /* Delay on I2S data. */ \
false, /* No DMA split. */ \
usartI2sJustifyLeft,/* Data is left-justified within the frame */ \
false /* Stereo mode. */ \
}

Default configuration for I2S mode initialization structure.

Definition at line 686 of file em_usart.h.

Referenced by MIC_init().

#define USART_INITIRDA_DEFAULT
Value:
{ \
{ \
usartEnable, /* Enable RX/TX when initialization is complete. */ \
0, /* Use current configured reference clock for configuring baud rate. */ \
115200, /* 115200 bits/s. */ \
usartOVS16, /* 16x oversampling. */ \
usartDatabits8, /* 8 data bits. */ \
usartEvenParity, /* Even parity. */ \
usartStopbits1, /* 1 stop bit. */ \
false, /* Do not disable majority vote. */ \
false, /* Not USART PRS input mode. */ \
0, /* PRS channel 0. */ \
false, /* Auto CS functionality enable/disable switch */ \
0, /* Auto CS Hold cycles */ \
0, /* Auto CS Setup cycles */ \
usartHwFlowControlNone /* No HW flow control */ \
}, \
false, /* Rx invert disabled. */ \
false, /* Filtering disabled. */ \
usartIrDAPwTHREE, /* Pulse width is set to ONE. */ \
false, /* Routing to PRS is disabled. */ \
0 /* PRS channel 0. */ \
}

Default configuration for IrDA mode initialization structure.

Definition at line 590 of file em_usart.h.

#define USART_INITPRSTRIGGER_DEFAULT
Value:
{ \
false, /* Do not enable autoTX triggering. */ \
false, /* Do not enable receive triggering. */ \
false, /* Do not enable transmit triggering. */ \
0 /* Set default channel to zero. */ \
}

Default configuration for USART PRS triggering structure.

Definition at line 402 of file em_usart.h.

#define USART_INITSYNC_DEFAULT
Value:
{ \
usartEnable, /* Enable RX/TX when initialization is complete. */ \
0, /* Use current configured reference clock for configuring baud rate. */ \
1000000, /* 1 Mbits/s. */ \
usartDatabits8, /* 8 databits. */ \
true, /* Master mode. */ \
false, /* Send least significant bit first. */ \
usartClockMode0, /* Clock idle low, sample on rising edge. */ \
false, /* Not USART PRS input mode. */ \
0, /* PRS channel 0. */ \
false, /* No AUTOTX mode. */ \
false, /* No AUTOCS mode. */ \
0, /* Auto CS Hold cycles. */ \
0 /* Auto CS Setup cycles. */ \
}

Default configuration for USART sync initialization structure.

Definition at line 502 of file em_usart.h.

Referenced by MICROSD_Init(), and SPIDRV_Init().

#define usartIrDAPrsCh0   0U

Deprecated PRS channel selector value. New code should use an integer instead.

Definition at line 210 of file em_usart.h.

Typedef Documentation

typedef uint8_t USART_PRS_Channel_t

PRS Channel type

Definition at line 206 of file em_usart.h.

Enumeration Type Documentation

Clock polarity/phase mode.

Enumerator
usartClockMode0 

Clock idle low, sample on rising edge.

usartClockMode1 

Clock idle low, sample on falling edge.

usartClockMode2 

Clock idle high, sample on falling edge.

usartClockMode3 

Clock idle high, sample on rising edge.

Definition at line 176 of file em_usart.h.

Databit selection.

Enumerator
usartDatabits4 

4 data bits (not available for UART).

usartDatabits5 

5 data bits (not available for UART).

usartDatabits6 

6 data bits (not available for UART).

usartDatabits7 

7 data bits (not available for UART).

usartDatabits8 

8 data bits.

usartDatabits9 

9 data bits.

usartDatabits10 

10 data bits (not available for UART).

usartDatabits11 

11 data bits (not available for UART).

usartDatabits12 

12 data bits (not available for UART).

usartDatabits13 

13 data bits (not available for UART).

usartDatabits14 

14 data bits (not available for UART).

usartDatabits15 

15 data bits (not available for UART).

usartDatabits16 

16 data bits (not available for UART).

Definition at line 104 of file em_usart.h.

Enable selection.

Enumerator
usartDisable 

Disable both receiver and transmitter.

usartEnableRx 

Enable receiver only, transmitter disabled.

usartEnableTx 

Enable transmitter only, receiver disabled.

usartEnable 

Enable both receiver and transmitter.

Definition at line 121 of file em_usart.h.

I2S format selection.

Enumerator
usartI2sFormatW32D32 

32-bit word, 32-bit data.

usartI2sFormatW32D24M 

32-bit word, 32-bit data with 8 lsb masked.

usartI2sFormatW32D24 

32-bit word, 24-bit data.

usartI2sFormatW32D16 

32-bit word, 16-bit data.

usartI2sFormatW32D8 

32-bit word, 8-bit data.

usartI2sFormatW16D16 

16-bit word, 16-bit data.

usartI2sFormatW16D8 

16-bit word, 8-bit data.

usartI2sFormatW8D8 

8-bit word, 8-bit data.

Definition at line 260 of file em_usart.h.

I2S frame data justify.

Enumerator
usartI2sJustifyLeft 

Data is left-justified within the frame.

usartI2sJustifyRight 

Data is right-justified within the frame.

Definition at line 272 of file em_usart.h.

Pulse width selection for IrDA mode.

Enumerator
usartIrDAPwONE 

IrDA pulse width is 1/16 for OVS=0 and 1/8 for OVS=1

usartIrDAPwTWO 

IrDA pulse width is 2/16 for OVS=0 and 2/8 for OVS=1

usartIrDAPwTHREE 

IrDA pulse width is 3/16 for OVS=0 and 3/8 for OVS=1

usartIrDAPwFOUR 

IrDA pulse width is 4/16 for OVS=0 and 4/8 for OVS=1

Definition at line 191 of file em_usart.h.

Oversampling selection, used for asynchronous operation.

Enumerator
usartOVS16 

16x oversampling (normal).

usartOVS8 

8x oversampling.

usartOVS6 

6x oversampling.

usartOVS4 

4x oversampling.

Definition at line 136 of file em_usart.h.

Parity selection, mainly used for asynchronous operation.

Enumerator
usartNoParity 

No parity.

usartEvenParity 

Even parity.

usartOddParity 

Odd parity.

Definition at line 144 of file em_usart.h.

Stop bits selection, used for asynchronous operation.

Enumerator
usartStopbits0p5 

0.5 stop bits.

usartStopbits1 

1 stop bits.

usartStopbits1p5 

1.5 stop bits.

usartStopbits2 

2 stop bits.

Definition at line 151 of file em_usart.h.

Function Documentation

static void prsIrInput ( USART_TypeDef usart,
USART_PRS_Channel_t  ch 
)
static

Configure a PRS channel as USART Ir input.

Parameters
[in]usartA pointer to the USART/UART peripheral register block.
[in]chPRS channel.

Definition at line 213 of file em_usart.c.

References _USART_IRCTRL_IRPRSSEL_SHIFT, USART_TypeDef::IRCTRL, PRS, USART0, USART1, and USART_IRCTRL_IRPRSEN.

Referenced by USARTn_InitIrDA().

static void prsRxInput ( USART_TypeDef usart,
USART_PRS_Channel_t  ch 
)
static

Configure a PRS channel as USART Rx input.

Parameters
[in]usartA pointer to the USART/UART peripheral register block.
[in]chPRS channel.

Definition at line 185 of file em_usart.c.

References _USART_INPUT_RXPRSSEL_SHIFT, USART_TypeDef::CTRLX, USART_TypeDef::INPUT, PRS, USART0, USART1, and USART_INPUT_RXPRS.

Referenced by USART_InitAsync(), and USART_InitSync().

static void prsTriggerInput ( USART_TypeDef usart,
USART_PRS_Channel_t  ch 
)
static

Configure a PRS channel as USART Trigger input.

Parameters
[in]usartA pointer to the USART/UART peripheral register block.
[in]chPRS channel.

Definition at line 240 of file em_usart.c.

References _USART_TRIGCTRL_TSEL_MASK, _USART_TRIGCTRL_TSEL_SHIFT, PRS, USART_TypeDef::TRIGCTRL, USART0, and USART1.

Referenced by USART_InitPrsTrigger().

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).

Parameters
[in]usartA pointer to the USART/UART peripheral register block.
[in]refFreqUSART/UART reference clock frequency in Hz. If set to 0, the currently configured reference clock is assumed.
[in]baudrateBaudrate to try to achieve for USART/UART.
[in]ovsOversampling to be used. Normal is 16x oversampling but lower oversampling may be used to achieve higher rates or better baudrate accuracy in some cases. Notice that lower oversampling frequency makes the channel more vulnerable to bit faults during reception due to clock inaccuracies compared to the link partner.

Definition at line 282 of file em_usart.c.

References _USART_CTRL_OVS_MASK, USART_TypeDef::CLKDIV, CMU_ClockFreqGet(), cmuClock_HFPER, USART_TypeDef::CTRL, usartOVS16, usartOVS4, usartOVS6, and usartOVS8.

Referenced by USART_InitAsync().

uint32_t USART_BaudrateCalc ( uint32_t  refFreq,
uint32_t  clkdiv,
bool  syncmode,
USART_OVS_TypeDef  ovs 
)

Calculate baudrate for USART/UART given reference frequency, clock division, and oversampling rate (if async mode).

This function returns the baudrate that a USART/UART module will use if configured with the given frequency, clock divisor, and mode. Notice that this function will not use the hardware configuration. It can be used to determine if a given configuration is sufficiently accurate for the application.

Parameters
[in]refFreqUSART/UART HF peripheral frequency used.
[in]clkdivA clock division factor to be used.
[in]syncmode
  • True - synchronous mode operation.
  • False - asynchronous mode operation.
[in]ovsOversampling used if in asynchronous mode. Not used if syncmode is true.
Returns
Baudrate with given settings.

Definition at line 414 of file em_usart.c.

References usartOVS16, usartOVS6, and usartOVS8.

Referenced by USART_BaudrateGet().

uint32_t USART_BaudrateGet ( USART_TypeDef usart)

Get the current baudrate for USART/UART.

This function returns the actual baudrate (not considering oscillator inaccuracies) used by a USART/UART peripheral.

Parameters
[in]usartA pointer to the USART/UART peripheral register block.
Returns
The current baudrate.

Definition at line 545 of file em_usart.c.

References _USART_CTRL_OVS_MASK, USART_TypeDef::CLKDIV, CMU_ClockFreqGet(), cmuClock_HFPER, USART_TypeDef::CTRL, USART_BaudrateCalc(), and USART_CTRL_SYNC.

Referenced by SPIDRV_GetBitrate().

void USART_BaudrateSyncSet ( USART_TypeDef usart,
uint32_t  refFreq,
uint32_t  baudrate 
)

Configure the USART operating in synchronous mode to use a given baudrate (or as close as possible to a specified baudrate).

The configuration will be set to use a baudrate <= the specified baudrate to ensure that the baudrate does not exceed the specified value.

The fractional clock division is suppressed, although the hardware design allows it. It could cause half clock cycles to exceed a specified limit and thus potentially violate specifications for the slave device. In some special situations, a fractional clock division may be useful even in synchronous mode, but in those cases it must be directly adjusted, possibly assisted by USART_BaudrateCalc():

Parameters
[in]usartA pointer to the USART peripheral register block. (Cannot be used on UART modules.)
[in]refFreqA USART reference clock frequency in Hz that will be used. If set to 0, the currently-configured reference clock is assumed.
[in]baudrateBaudrate to try to achieve for USART.

Definition at line 594 of file em_usart.c.

References USART_TypeDef::CLKDIV, CMU_ClockFreqGet(), and cmuClock_HFPER.

Referenced by MICROSD_SpiClkFast(), MICROSD_SpiClkSlow(), SPIDRV_SetBitrate(), and USART_InitSync().

void USART_Enable ( USART_TypeDef usart,
USART_Enable_TypeDef  enable 
)

Enable/disable USART/UART receiver and/or transmitter.

Notice that this function does not do any configuration. Enabling should normally be done after initialization (if not enabled as part of initialization).

Parameters
[in]usartA pointer to the USART/UART peripheral register block.
[in]enableSelect the status for the receiver/transmitter.

Definition at line 640 of file em_usart.c.

References _USART_CMD_RXEN_MASK, _USART_CMD_TXEN_MASK, USART_TypeDef::CMD, and usartDisable.

Referenced by RETARGET_SerialInit(), UARTDRV_InitUart(), and USART_InitI2s().

void USART_InitAsync ( USART_TypeDef usart,
const USART_InitAsync_TypeDef init 
)

Initialize USART/UART for normal asynchronous mode.

This function will configure basic settings to operate in normal asynchronous mode.

A special control setup not covered by this function must be done after using this function by direct modification of the CTRL register.

Notice that pins used by the USART/UART module must be properly configured by the user explicitly for the USART/UART to work as intended. (When configuring pins, remember to consider the sequence of configuration to avoid unintended pulses/glitches on output pins.)

Parameters
[in]usartA pointer to the USART/UART peripheral register block.
[in]initA pointer to the initialization structure used to configure the basic async setup.

Definition at line 691 of file em_usart.c.

References _USART_ROUTEPEN_CTSPEN_MASK, _USART_ROUTEPEN_RTSPEN_MASK, _USART_TIMING_CSHOLD_MASK, _USART_TIMING_CSHOLD_SHIFT, _USART_TIMING_CSSETUP_MASK, _USART_TIMING_CSSETUP_SHIFT, USART_InitAsync_TypeDef::autoCsEnable, USART_InitAsync_TypeDef::autoCsHold, USART_InitAsync_TypeDef::autoCsSetup, USART_InitAsync_TypeDef::baudrate, USART_TypeDef::CMD, USART_TypeDef::CTRL, USART_InitAsync_TypeDef::databits, USART_InitAsync_TypeDef::enable, USART_TypeDef::FRAME, GPIO, USART_InitAsync_TypeDef::hwFlowControl, USART_InitAsync_TypeDef::mvdis, USART_InitAsync_TypeDef::oversampling, USART_InitAsync_TypeDef::parity, USART_InitAsync_TypeDef::prsRxCh, USART_InitAsync_TypeDef::prsRxEnable, prsRxInput(), USART_InitAsync_TypeDef::refFreq, USART_TypeDef::ROUTEPEN, USART_InitAsync_TypeDef::stopbits, USART_TypeDef::TIMING, USART_BaudrateAsyncSet(), USART_CTRL_AUTOCS, USART_CTRL_MVDIS, USART_CTRLX_CTSEN, and USART_Reset().

Referenced by BSP_BccInit(), RETARGET_SerialInit(), UARTDRV_InitUart(), and USARTn_InitIrDA().

void USART_InitI2s ( USART_TypeDef usart,
USART_InitI2s_TypeDef init 
)

Initialize USART for I2S mode.

This function will configure basic settings to operate in I2S mode.

A special control setup not covered by this function must be done after using this function by direct modification of the CTRL and I2SCTRL registers.

Notice that pins used by the USART module must be properly configured by the user explicitly for the USART to work as intended. (When configuring pins, remember to consider the sequence of configuration to avoid unintended pulses/glitches on output pins.)

Parameters
[in]usartA pointer to the USART peripheral register block. (UART does not support this mode.)
[in]initA pointer to the initialization structure used to configure the basic I2S setup.
Note
This function does not apply to all USART's. See the chip Reference Manual.

Definition at line 923 of file em_usart.c.

References USART_InitI2s_TypeDef::delay, USART_InitI2s_TypeDef::dmaSplit, USART_InitSync_TypeDef::enable, USART_InitI2s_TypeDef::format, USART_TypeDef::I2SCTRL, USART_InitI2s_TypeDef::justify, USART_InitI2s_TypeDef::mono, USART_InitI2s_TypeDef::sync, USART_Enable(), USART_I2SCTRL_DELAY, USART_I2SCTRL_DMASPLIT, USART_I2SCTRL_EN, USART_I2SCTRL_MONO, USART_InitSync(), and usartDisable.

Referenced by MIC_init().

__STATIC_INLINE void USART_InitIrDA ( const USART_InitIrDA_TypeDef init)

Initialization DEFAULT_IRDA_USART for asynchronous IrDA mode.

This function will configure basic settings in order to operate in asynchronous IrDA mode.

Special control setup not covered by this function must be done after using this function by direct modification of the CTRL and IRCTRL registers.

Notice that pins used by the USART/UART module must be properly configured by the user explicitly for the USART/UART to work as intended. (When configuring pins, one should remember to consider the sequence of configuration to avoid unintended pulses/glitches on output pins.)

Parameters
[in]initPointer to initialization structure used to configure asynchronous IrDA setup.
Deprecated:
Deprecated function. New code should use USARTn_InitIrDA(). This function uses DEFAULT_IRDA_USART, which unless otherwise specified, is USART0 on most devices, and USART1 on devices that don't have a USART0.

Definition at line 767 of file em_usart.h.

References USART0, USART1, and USARTn_InitIrDA().

void USART_InitPrsTrigger ( USART_TypeDef usart,
const USART_PrsTriggerInit_TypeDef init 
)

Initialize the automatic transmissions using PRS channel as a trigger.

Note
Initialize USART with USART_Init() before setting up the PRS configuration.
Parameters
[in]usartA pointer to USART to configure.
[in]initA pointer to the initialization structure.

Definition at line 960 of file em_usart.c.

References _USART_TRIGCTRL_AUTOTXTEN_MASK, _USART_TRIGCTRL_RXTEN_MASK, _USART_TRIGCTRL_TXTEN_MASK, USART_PrsTriggerInit_TypeDef::autoTxTriggerEnable, USART_PrsTriggerInit_TypeDef::prsTriggerChannel, prsTriggerInput(), USART_PrsTriggerInit_TypeDef::rxTriggerEnable, USART_TypeDef::TRIGCTRL, USART_PrsTriggerInit_TypeDef::txTriggerEnable, USART_TRIGCTRL_AUTOTXTEN, USART_TRIGCTRL_RXTEN, and USART_TRIGCTRL_TXTEN.

void USART_InitSync ( USART_TypeDef usart,
const USART_InitSync_TypeDef init 
)

Initialize USART for synchronous mode.

This function will configure basic settings to operate in synchronous mode.

A special control setup not covered by this function must be done after using this function by direct modification of the CTRL register.

Notice that pins used by the USART module must be properly configured by the user explicitly for the USART to work as intended. (When configuring pins remember to consider the sequence of configuration to avoid unintended pulses/glitches on output pins.)

Parameters
[in]usartA pointer to the USART peripheral register block. (UART does not support this mode.)
[in]initA pointer to the initialization structure used to configure basic async setup.

Definition at line 786 of file em_usart.c.

References _USART_TIMING_CSHOLD_MASK, _USART_TIMING_CSHOLD_SHIFT, _USART_TIMING_CSSETUP_MASK, _USART_TIMING_CSSETUP_SHIFT, USART_InitSync_TypeDef::autoCsEnable, USART_InitSync_TypeDef::autoCsHold, USART_InitSync_TypeDef::autoCsSetup, USART_InitSync_TypeDef::autoTx, USART_InitSync_TypeDef::baudrate, USART_InitSync_TypeDef::clockMode, USART_TypeDef::CMD, USART_TypeDef::CTRL, USART_InitSync_TypeDef::databits, USART_InitSync_TypeDef::enable, USART_TypeDef::FRAME, USART_InitSync_TypeDef::master, USART_InitSync_TypeDef::msbf, USART_InitSync_TypeDef::prsRxCh, USART_InitSync_TypeDef::prsRxEnable, prsRxInput(), USART_InitSync_TypeDef::refFreq, USART_TypeDef::TIMING, USART_BaudrateSyncSet(), USART_CMD_MASTEREN, USART_CTRL_AUTOCS, USART_CTRL_AUTOTX, USART_CTRL_MSBF, USART_CTRL_SYNC, USART_FRAME_PARITY_DEFAULT, USART_FRAME_STOPBITS_DEFAULT, and USART_Reset().

Referenced by ICM20648_spiInit(), MICROSD_Init(), SPI_TFT_Init(), SPIDRV_Init(), and USART_InitI2s().

__STATIC_INLINE void USART_IntClear ( USART_TypeDef usart,
uint32_t  flags 
)

Clear one or more pending USART interrupts.

Parameters
[in]usartPointer to USART/UART peripheral register block.
[in]flagsPending USART/UART interrupt source(s) to clear. Use one or more valid interrupt flags for the USART module (USART_IF_nnn) OR'ed together.

Definition at line 791 of file em_usart.h.

References USART_TypeDef::IFC.

Referenced by RETARGET_SerialInit(), and UARTDRV_InitUart().

__STATIC_INLINE void USART_IntDisable ( USART_TypeDef usart,
uint32_t  flags 
)

Disable one or more USART interrupts.

Parameters
[in]usartPointer to USART/UART peripheral register block.
[in]flagsUSART/UART interrupt source(s) to disable. Use one or more valid interrupt flags for the USART module (USART_IF_nnn) OR'ed together.

Definition at line 811 of file em_usart.h.

References USART_TypeDef::IEN.

Referenced by disableRxInterrupt().

__STATIC_INLINE void USART_IntEnable ( USART_TypeDef usart,
uint32_t  flags 
)

Enable one or more USART interrupts.

Note
Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using USART_IntClear() prior to enabling the interrupt.
Parameters
[in]usartPointer to USART/UART peripheral register block.
[in]flagsUSART/UART interrupt source(s) to enable. Use one or more valid interrupt flags for the USART module (USART_IF_nnn) OR'ed together.

Definition at line 832 of file em_usart.h.

References USART_TypeDef::IEN.

Referenced by enableRxInterrupt(), and RETARGET_SerialInit().

__STATIC_INLINE uint32_t USART_IntGet ( USART_TypeDef usart)

Get pending USART interrupt flags.

Note
The event bits are not cleared by the use of this function.
Parameters
[in]usartPointer to USART/UART peripheral register block.
Returns
USART/UART interrupt source(s) pending. Returns one or more valid interrupt flags for the USART module (USART_IF_nnn) OR'ed together.

Definition at line 851 of file em_usart.h.

References USART_TypeDef::IF.

__STATIC_INLINE uint32_t USART_IntGetEnabled ( USART_TypeDef usart)

Get enabled and pending USART interrupt flags. Useful for handling more interrupt sources in the same interrupt handler.

Parameters
[in]usartPointer to USART/UART peripheral register block.
Note
Interrupt flags are not cleared by the use of this function.
Returns
Pending and enabled USART interrupt sources. The return value is the bitwise AND combination of
  • the OR combination of enabled interrupt sources in USARTx_IEN_nnn register (USARTx_IEN_nnn) and
  • the OR combination of valid interrupt flags of the USART module (USARTx_IF_nnn).

Definition at line 875 of file em_usart.h.

References USART_TypeDef::IEN, and USART_TypeDef::IF.

__STATIC_INLINE void USART_IntSet ( USART_TypeDef usart,
uint32_t  flags 
)

Set one or more pending USART interrupts from SW.

Parameters
[in]usartPointer to USART/UART peripheral register block.
[in]flagsUSART/UART interrupt source(s) to set to pending. Use one or more valid interrupt flags for the USART module (USART_IF_nnn) OR'ed together.

Definition at line 898 of file em_usart.h.

References USART_TypeDef::IFS.

uint8_t USART_Rx ( USART_TypeDef usart)

Receive one 4-8 bit frame, (or part of 10-16 bit frame).

This function is normally used to receive one frame when operating with frame length 4-8 bits. See USART_RxExt() for reception of 9 bit frames.

Notice that possible parity/stop bits in asynchronous mode are not considered part of a specified frame bit length.

Note
This function will stall if the buffer is empty until data is received. Alternatively, the user can explicitly check whether data is available. If data is available, call USART_RxDataGet() to read the RXDATA register directly.
Parameters
[in]usartA pointer to the USART/UART peripheral register block.
Returns
Data received.

Definition at line 1089 of file em_usart.c.

References USART_TypeDef::RXDATA, USART_TypeDef::STATUS, and USART_STATUS_RXDATAV.

Referenced by ICM20648_bankSelect(), ICM20648_registerRead(), ICM20648_registerWrite(), and SPI_TFT_WriteRegister().

__STATIC_INLINE uint8_t USART_RxDataGet ( USART_TypeDef usart)

Receive one 4-8 bit frame, (or part of 10-16 bit frame).

This function is used to quickly receive one 4-8 bits frame by reading the RXDATA register directly, without checking the STATUS register for the RXDATAV flag. This can be useful from the RXDATAV interrupt handler, i.e., waiting is superfluous, in order to quickly read the received data. Please refer to USART_RxDataXGet() for reception of 9 bit frames.

Note
Since this function does not check whether the RXDATA register actually holds valid data, it should only be used in situations when it is certain that there is valid data, ensured by some external program routine, e.g., when handling an RXDATAV interrupt. The USART_Rx() is normally a better choice if the validity of the RXDATA register is not certain.
Notice that possible parity/stop bits in asynchronous mode are not considered part of specified frame bit length.
Parameters
[in]usartPointer to USART/UART peripheral register block.
Returns
Data received.

Definition at line 957 of file em_usart.h.

References USART_TypeDef::RXDATA.

__STATIC_INLINE uint16_t USART_RxDataXGet ( USART_TypeDef usart)

Receive one 4-9 bit frame, (or part of 10-16 bit frame) with extended information.

This function is used to quickly receive one 4-9 bit frame, (or part of 10-16 bit frame) with extended information by reading the RXDATAX register directly, without checking the STATUS register for the RXDATAV flag. This can be useful from the RXDATAV interrupt handler, i.e., waiting is superfluous, in order to quickly read the received data.

Note
Since this function does not check whether the RXDATAX register actually holds valid data, it should only be used in situations when it is certain that there is valid data, ensured by some external program routine, e.g., when handling an RXDATAV interrupt. The USART_RxExt() is normally a better choice if the validity of the RXDATAX register is not certain.
Notice that possible parity/stop bits in asynchronous mode are not considered part of specified frame bit length.
Parameters
[in]usartPointer to USART/UART peripheral register block.
Returns
Data received.

Definition at line 1063 of file em_usart.h.

References USART_TypeDef::RXDATAX.

uint16_t USART_RxDouble ( USART_TypeDef usart)

Receive two 4-8 bit frames or one 10-16 bit frame.

This function is normally used to receive one frame when operating with frame length 10-16 bits. See USART_RxDoubleExt() for reception of two 9 bit frames.

Notice that possible parity/stop bits in asynchronous mode are not considered part of a specified frame bit length.

Note
This function will stall if the buffer is empty until data is received. Alternatively, the user can explicitly check whether data is available. If data is available, call USART_RxDoubleGet() to read the RXDOUBLE register directly.
Parameters
[in]usartA pointer to the USART/UART peripheral register block.
Returns
Data received.

Definition at line 1121 of file em_usart.c.

References USART_TypeDef::RXDOUBLE, USART_TypeDef::STATUS, and USART_STATUS_RXFULL.

uint32_t USART_RxDoubleExt ( USART_TypeDef usart)

Receive two 4-9 bit frames, or one 10-16 bit frame with extended information.

This function is normally used to receive one frame when operating with frame length 10-16 bits and additional RX status information is required.

Notice that possible parity/stop bits in asynchronous mode are not considered part of a specified frame bit length.

Note
This function will stall if buffer is empty until data is received. Alternatively, the user can explicitly check whether data is available. If data is available, call USART_RxDoubleXGet() to read the RXDOUBLEX register directly.
Parameters
[in]usartA pointer to the USART/UART peripheral register block.
Returns
Data received.

Definition at line 1153 of file em_usart.c.

References USART_TypeDef::RXDOUBLEX, USART_TypeDef::STATUS, and USART_STATUS_RXFULL.

__STATIC_INLINE uint16_t USART_RxDoubleGet ( USART_TypeDef usart)

Receive two 4-8 bit frames, or one 10-16 bit frame.

This function is used to quickly receive one 10-16 bits frame or two 4-8 bit frames by reading the RXDOUBLE register directly, without checking the STATUS register for the RXDATAV flag. This can be useful from the RXDATAV interrupt handler, i.e., waiting is superfluous, in order to quickly read the received data. This function is normally used to receive one frame when operating with frame length 10-16 bits. Please refer to USART_RxDoubleXGet() for reception of two 9 bit frames.

Note
Since this function does not check whether the RXDOUBLE register actually holds valid data, it should only be used in situations when it is certain that there is valid data, ensured by some external program routine, e.g., when handling an RXDATAV interrupt. The USART_RxDouble() is normally a better choice if the validity of the RXDOUBLE register is not certain.
Notice that possible parity/stop bits in asynchronous mode are not considered part of specified frame bit length.
Parameters
[in]usartPointer to USART/UART peripheral register block.
Returns
Data received.

Definition at line 994 of file em_usart.h.

References USART_TypeDef::RXDOUBLE.

__STATIC_INLINE uint32_t USART_RxDoubleXGet ( USART_TypeDef usart)

Receive two 4-9 bit frames, or one 10-16 bit frame with extended information.

This function is used to quickly receive one 10-16 bits frame or two 4-9 bit frames by reading the RXDOUBLEX register directly, without checking the STATUS register for the RXDATAV flag. This can be useful from the RXDATAV interrupt handler, i.e., waiting is superfluous, in order to quickly read the received data.

Note
Since this function does not check whether the RXDOUBLEX register actually holds valid data, it should only be used in situations when it is certain that there is valid data, ensured by some external program routine, e.g., when handling an RXDATAV interrupt. The USART_RxDoubleExt() is normally a better choice if the validity of the RXDOUBLEX register is not certain.
Notice that possible parity/stop bits in asynchronous mode are not considered part of specified frame bit length.
Parameters
[in]usartPointer to USART/UART peripheral register block.
Returns
Data received.

Definition at line 1029 of file em_usart.h.

References USART_TypeDef::RXDOUBLEX.

uint16_t USART_RxExt ( USART_TypeDef usart)

Receive one 4-9 bit frame (or part of 10-16 bit frame) with extended information.

This function is normally used to receive one frame when operating with frame length 4-9 bits and additional RX status information is required.

Notice that possible parity/stop bits in asynchronous mode are not considered part of a specified frame bit length.

Note
This function will stall if the buffer is empty until data is received. Alternatively, the user can explicitly check whether data is available. If data is available, call USART_RxDataXGet() to read the RXDATAX register directly.
Parameters
[in]usartA pointer to the USART/UART peripheral register block.
Returns
Data received.

Definition at line 1185 of file em_usart.c.

References USART_TypeDef::RXDATAX, USART_TypeDef::STATUS, and USART_STATUS_RXDATAV.

uint8_t USART_SpiTransfer ( USART_TypeDef usart,
uint8_t  data 
)

Perform one 8 bit frame SPI transfer.

Note
This function will stall if the transmit buffer is full. When a transmit buffer becomes available, data is written and the function will wait until data is fully transmitted. The SPI return value is then read out and returned.
Parameters
[in]usartA pointer to the USART peripheral register block.
[in]dataData to transmit.
Returns
Data received.

Definition at line 1212 of file em_usart.c.

References USART_TypeDef::RXDATA, USART_TypeDef::STATUS, USART_TypeDef::TXDATA, USART_STATUS_TXBL, and USART_STATUS_TXC.

Referenced by BOARD_flashDeepPowerDown(), and MICROSD_XferSpi().

__STATIC_INLINE uint32_t USART_StatusGet ( USART_TypeDef usart)

Get USART STATUS register.

Parameters
[in]usartPointer to USART/UART peripheral register block.
Returns
STATUS register value.

Definition at line 918 of file em_usart.h.

References USART_TypeDef::STATUS.

void USART_Tx ( USART_TypeDef usart,
uint8_t  data 
)

Transmit one 4-9 bit frame.

Depending on the frame length configuration, 4-8 (least significant) bits from data are transmitted. If the frame length is 9, 8 bits are transmitted from data and one bit as specified by CTRL register, BIT8DV field. See USART_TxExt() for transmitting 9 bit frame with full control of all 9 bits.

Notice that possible parity/stop bits in asynchronous mode are not considered part of a specified frame bit length.

Note
This function will stall if the buffer is full until the buffer becomes available.
Parameters
[in]usartA pointer to the USART/UART peripheral register block.
[in]dataData to transmit. See details above for more information.

Definition at line 1245 of file em_usart.c.

References USART_TypeDef::STATUS, USART_TypeDef::TXDATA, and USART_STATUS_TXBL.

Referenced by ICM20648_bankSelect(), ICM20648_registerRead(), ICM20648_registerWrite(), SPI_TFT_WriteRegister(), and UARTDRV_ForceTransmit().

void USART_TxDouble ( USART_TypeDef usart,
uint16_t  data 
)

Transmit two 4-9 bit frames or one 10-16 bit frame.

Depending on the frame length configuration, 4-8 (least significant) bits from each byte in data are transmitted. If frame length is 9, 8 bits are transmitted from each byte in data adding one bit as specified by the CTRL register, BIT8DV field, to each byte. See USART_TxDoubleExt() for transmitting two 9 bit frames with full control of all 9 bits.

If the frame length is 10-16, 10-16 (least significant) bits from data are transmitted.

Notice that possible parity/stop bits in asynchronous mode are not considered part of a specified frame bit length.

Note
This function will stall if the buffer is full until the buffer becomes available.
Parameters
[in]usartA pointer to the USART/UART peripheral register block.
[in]dataData to transmit, the least significant byte holds the frame transmitted first. See details above for more info.

Definition at line 1280 of file em_usart.c.

References USART_TypeDef::STATUS, USART_TypeDef::TXDOUBLE, and USART_STATUS_TXBL.

void USART_TxDoubleExt ( USART_TypeDef usart,
uint32_t  data 
)

Transmit two 4-9 bit frames or one 10-16 bit frame with extended control.

Notice that possible parity/stop bits in asynchronous mode are not considered part of a specified frame bit length.

Note
This function will stall if the buffer is full until the buffer becomes available.
Parameters
[in]usartA pointer to the USART/UART peripheral register block.
[in]dataData to transmit with extended control. Contains two 16 bit words concatenated. Least significant word holds the frame transmitted first. If the frame length is 4-9, two frames with 4-9 least significant bits from each 16 bit word are transmitted.
If the frame length is 10-16 bits, 8 data bits are taken from the least significant 16 bit word and the remaining bits from the other 16 bit word.
Additional control bits are available as documented in the reference manual (set to 0 if not used). For 10-16 bit frame length, these control bits are taken from the most significant 16 bit word.

Definition at line 1315 of file em_usart.c.

References USART_TypeDef::STATUS, USART_TypeDef::TXDOUBLEX, and USART_STATUS_TXBL.

void USART_TxExt ( USART_TypeDef usart,
uint16_t  data 
)

Transmit one 4-9 bit frame with extended control.

Notice that possible parity/stop bits in asynchronous mode are not considered part of a specified frame bit length.

Note
This function will stall if the buffer is full until the buffer becomes available.
Parameters
[in]usartA pointer to the USART/UART peripheral register block.
[in]dataData to transmit with extended control. Least significant bit contains frame bits. Additional control bits are available as documented in the reference manual (set to 0 if not used).

Definition at line 1342 of file em_usart.c.

References USART_TypeDef::STATUS, USART_TypeDef::TXDATAX, and USART_STATUS_TXBL.

void USARTn_InitIrDA ( USART_TypeDef usart,
const USART_InitIrDA_TypeDef init 
)

Initialize USART for asynchronous IrDA mode.

This function will configure basic settings to operate in asynchronous IrDA mode.

A special control setup not covered by this function must be done after using this function by direct modification of the CTRL and IRCTRL registers.

Notice that pins used by the USART/UART module must be properly configured by the user explicitly for the USART/UART to work as intended. (When configuring pins, remember to consider the sequence of configuration to avoid unintended pulses/glitches on output pins.)

Parameters
[in]usartA pointer to the USART peripheral register block.
[in]initA pointer to the initialization structure used to configure async IrDA setup.
Note
Not all USART instances support IrDA. See the data sheet for your device.

Definition at line 867 of file em_usart.c.

References _USART_IRCTRL_IRFILT_SHIFT, USART_InitIrDA_TypeDef::async, USART_TypeDef::CTRL, USART_TypeDef::IRCTRL, USART_InitIrDA_TypeDef::irFilt, USART_InitIrDA_TypeDef::irPrsEn, USART_InitIrDA_TypeDef::irPrsSel, USART_InitIrDA_TypeDef::irPw, USART_InitIrDA_TypeDef::irRxInv, prsIrInput(), USART_CTRL_RXINV, USART_CTRL_TXINV, USART_InitAsync(), and USART_IRCTRL_IREN.

Referenced by USART_InitIrDA().