LEUART - Low Energy UART#

Low Energy Universal Asynchronous Receiver/Transmitter (LEUART) Peripheral API.

This module contains functions to control the LEUART peripheral of Silicon Labs 32-bit MCUs and SoCs. The LEUART module provides the full UART communication using a low frequency 32.768 kHz clock and has special features for communication without the CPU intervention.

Modules#

LEUART_Init_TypeDef

Enumerations#

enum
leuartDatabits8 = LEUART_CTRL_DATABITS_EIGHT
leuartDatabits9 = LEUART_CTRL_DATABITS_NINE
}

Data bit selection.

enum
leuartDisable = 0x0
leuartEnableRx = LEUART_CMD_RXEN
leuartEnableTx = LEUART_CMD_TXEN
leuartEnable = (LEUART_CMD_RXEN | LEUART_CMD_TXEN)
}

Enable selection.

enum
leuartNoParity = LEUART_CTRL_PARITY_NONE
leuartEvenParity = LEUART_CTRL_PARITY_EVEN
leuartOddParity = LEUART_CTRL_PARITY_ODD
}

Parity selection.

enum
leuartStopbits1 = LEUART_CTRL_STOPBITS_ONE
leuartStopbits2 = LEUART_CTRL_STOPBITS_TWO
}

Stop bits selection.

Functions#

uint32_t
LEUART_BaudrateCalc(uint32_t refFreq, uint32_t clkdiv)

Calculate the baudrate for the LEUART given reference frequency and clock division.

uint32_t
LEUART_BaudrateGet(LEUART_TypeDef *leuart)

Get the current baudrate for LEUART.

void
LEUART_BaudrateSet(LEUART_TypeDef *leuart, uint32_t refFreq, uint32_t baudrate)

Configure the baudrate (or as close as possible to a specified baudrate).

void
LEUART_Enable(LEUART_TypeDef *leuart, LEUART_Enable_TypeDef enable)

Enable/disable the LEUART receiver and/or transmitter.

void
LEUART_FreezeEnable(LEUART_TypeDef *leuart, bool enable)

LEUART register synchronization freeze control.

void
LEUART_Init(LEUART_TypeDef *leuart, LEUART_Init_TypeDef const *init)

Initialize LEUART.

void
LEUART_TxDmaInEM2Enable(LEUART_TypeDef *leuart, bool enable)

Enables handling of LEUART TX by DMA in EM2.

void
LEUART_RxDmaInEM2Enable(LEUART_TypeDef *leuart, bool enable)

Enables handling of LEUART RX by DMA in EM2.

void
LEUART_IntClear(LEUART_TypeDef *leuart, uint32_t flags)

Clear one or more pending LEUART interrupts.

void
LEUART_IntDisable(LEUART_TypeDef *leuart, uint32_t flags)

Disable one or more LEUART interrupts.

void
LEUART_IntEnable(LEUART_TypeDef *leuart, uint32_t flags)

Enable one or more LEUART interrupts.

uint32_t
LEUART_IntGet(LEUART_TypeDef *leuart)

Get pending LEUART interrupt flags.

uint32_t
LEUART_IntGetEnabled(LEUART_TypeDef *leuart)

Get enabled and pending LEUART interrupt flags.

void
LEUART_IntSet(LEUART_TypeDef *leuart, uint32_t flags)

Set one or more pending LEUART interrupts from SW.

uint32_t
LEUART_StatusGet(LEUART_TypeDef *leuart)

Get LEUART STATUS register.

void
LEUART_Reset(LEUART_TypeDef *leuart)

Reset LEUART to the same state that it was in after a hardware reset.

uint8_t
LEUART_Rx(LEUART_TypeDef *leuart)

Receive one 8 bit frame, (or part of 9 bit frame).

uint16_t
LEUART_RxExt(LEUART_TypeDef *leuart)

Receive one 8-9 bit frame with extended information.

void
LEUART_Tx(LEUART_TypeDef *leuart, uint8_t data)

Transmit one frame.

void
LEUART_TxExt(LEUART_TypeDef *leuart, uint16_t data)

Transmit one 8-9 bit frame with extended control.

uint8_t
LEUART_RxDataGet(LEUART_TypeDef *leuart)

Receive one 8 bit frame, (or part of a 9 bit frame).

uint16_t
LEUART_RxDataXGet(LEUART_TypeDef *leuart)

Receive one 8-9 bit frame, with extended information.

Macros#

#define

Default configuration for LEUART initialization structure.

Enumeration Documentation#

LEUART_Databits_TypeDef#

LEUART_Databits_TypeDef

Data bit selection.

Enumerator
leuartDatabits8

8 data bits.

leuartDatabits9

9 data bits.


Definition at line 54 of file platform/emlib/inc/em_leuart.h

LEUART_Enable_TypeDef#

LEUART_Enable_TypeDef

Enable selection.

Enumerator
leuartDisable

Disable both receiver and transmitter.

leuartEnableRx

Enable receiver only, transmitter disabled.

leuartEnableTx

Enable transmitter only, receiver disabled.

leuartEnable

Enable both receiver and transmitter.


Definition at line 60 of file platform/emlib/inc/em_leuart.h

LEUART_Parity_TypeDef#

LEUART_Parity_TypeDef

Parity selection.

Enumerator
leuartNoParity

No parity.

leuartEvenParity

Even parity.

leuartOddParity

Odd parity.


Definition at line 75 of file platform/emlib/inc/em_leuart.h

LEUART_Stopbits_TypeDef#

LEUART_Stopbits_TypeDef

Stop bits selection.

Enumerator
leuartStopbits1

1 stop bits.

leuartStopbits2

2 stop bits.


Definition at line 82 of file platform/emlib/inc/em_leuart.h

Function Documentation#

LEUART_BaudrateCalc#

uint32_t LEUART_BaudrateCalc (uint32_t refFreq, uint32_t clkdiv)

Calculate the baudrate for the LEUART given reference frequency and clock division.

Parameters
[in]refFreq

The LEUART peripheral frequency used.

[in]clkdiv

The clock division factor to be used.

This function returns the baudrate that a LEUART module will use if configured with the given frequency and clock divisor. 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.

Returns

  • A baudrate with given settings.


Definition at line 125 of file platform/emlib/src/em_leuart.c

LEUART_BaudrateGet#

uint32_t LEUART_BaudrateGet (LEUART_TypeDef * leuart)

Get the current baudrate for LEUART.

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

This function returns the actual baudrate (not considering the oscillator inaccuracies) used by the LEUART peripheral.

Returns

  • The current baudrate.


Definition at line 202 of file platform/emlib/src/em_leuart.c

LEUART_BaudrateSet#

void LEUART_BaudrateSet (LEUART_TypeDef * leuart, uint32_t refFreq, uint32_t baudrate)

Configure the baudrate (or as close as possible to a specified baudrate).

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

[in]refFreq

The LEUART reference clock frequency in Hz that will be used. If set to 0, the currently configured reference clock is assumed.

[in]baudrate

A baudrate to try to achieve for LEUART.

Note

  • The baudrate setting requires synchronization into the low-frequency domain. If the same register is modified before a previous update has completed, this function will stall until the previous synchronization has completed.


Definition at line 246 of file platform/emlib/src/em_leuart.c

LEUART_Enable#

void LEUART_Enable (LEUART_TypeDef * leuart, LEUART_Enable_TypeDef enable)

Enable/disable the LEUART receiver and/or transmitter.

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

[in]enable

Select status for receiver/transmitter.

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

Note

  • Enabling/disabling requires synchronization into the low-frequency domain. If the same register is modified before a previous update has completed, this function will stall until the previous synchronization has completed.


Definition at line 338 of file platform/emlib/src/em_leuart.c

LEUART_FreezeEnable#

void LEUART_FreezeEnable (LEUART_TypeDef * leuart, bool enable)

LEUART register synchronization freeze control.

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

[in]enable
  • True - enable freeze, modified registers are not propagated to the LF domain

  • False - disables freeze, modified registers are propagated to the LF domain

Some LEUART registers require synchronization into the low-frequency (LF) domain. The freeze feature allows for several such registers to be modified before passing them to the LF domain simultaneously (which takes place when the freeze mode is disabled).

Note

  • When enabling freeze mode, this function will wait for all current ongoing LEUART synchronization to the LF domain to complete (Normally synchronization will not be in progress.) However, for this reason, when using freeze mode, modifications of registers requiring LF synchronization should be done within one freeze enable/disable block to avoid unnecessary stalling.


Definition at line 385 of file platform/emlib/src/em_leuart.c

LEUART_Init#

void LEUART_Init (LEUART_TypeDef * leuart, LEUART_Init_TypeDef const * init)

Initialize LEUART.

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

[in]init

A pointer to the initialization structure used to configure basic async setup.

This function will configure basic settings to operate in normal asynchronous mode. Consider using LEUART_Reset() prior to this function if the state of configuration is not known, since only configuration settings specified by init are set.

Special control setup not covered by this function may be done either before or after using this function (but normally before enabling) by direct modification of the CTRL register.

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

Note

  • Initializing requires synchronization into the low-frequency domain. If the same register is modified before a previous update has completed, this function will stall until the previous synchronization has completed.


Definition at line 437 of file platform/emlib/src/em_leuart.c

LEUART_TxDmaInEM2Enable#

void LEUART_TxDmaInEM2Enable (LEUART_TypeDef * leuart, bool enable)

Enables handling of LEUART TX by DMA in EM2.

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

[in]enable

True - enables functionality False - disables functionality


Definition at line 636 of file platform/emlib/src/em_leuart.c

LEUART_RxDmaInEM2Enable#

void LEUART_RxDmaInEM2Enable (LEUART_TypeDef * leuart, bool enable)

Enables handling of LEUART RX by DMA in EM2.

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

[in]enable

True - enables functionality False - disables functionality


Definition at line 684 of file platform/emlib/src/em_leuart.c

LEUART_IntClear#

void LEUART_IntClear (LEUART_TypeDef * leuart, uint32_t flags)

Clear one or more pending LEUART interrupts.

Parameters
[in]leuart

Pointer to LEUART peripheral register block.

[in]flags

Pending LEUART interrupt source to clear. Use a bitwise logic OR combination of valid interrupt flags for LEUART module (LEUART_IF_nnn).


Definition at line 152 of file platform/emlib/inc/em_leuart.h

LEUART_IntDisable#

void LEUART_IntDisable (LEUART_TypeDef * leuart, uint32_t flags)

Disable one or more LEUART interrupts.

Parameters
[in]leuart

Pointer to LEUART peripheral register block.

[in]flags

LEUART interrupt sources to disable. Use a bitwise logic OR combination of valid interrupt flags for LEUART module (LEUART_IF_nnn).


Definition at line 168 of file platform/emlib/inc/em_leuart.h

LEUART_IntEnable#

void LEUART_IntEnable (LEUART_TypeDef * leuart, uint32_t flags)

Enable one or more LEUART interrupts.

Parameters
[in]leuart

Pointer to LEUART peripheral register block.

[in]flags

LEUART interrupt sources to enable. Use a bitwise logic OR combination of valid interrupt flags for LEUART module (LEUART_IF_nnn).

Note

  • Depending on the use, a pending interrupt may already be set prior to enabling the interrupt. To ignore a pending interrupt, consider using LEUART_IntClear() prior to enabling the interrupt.


Definition at line 189 of file platform/emlib/inc/em_leuart.h

LEUART_IntGet#

uint32_t LEUART_IntGet (LEUART_TypeDef * leuart)

Get pending LEUART interrupt flags.

Parameters
[in]leuart

Pointer to LEUART peripheral register block.

Note

  • The event bits are not cleared by the use of this function.

Returns

  • LEUART interrupt sources pending. A bitwise logic OR combination of valid interrupt flags for LEUART module (LEUART_IF_nnn).


Definition at line 208 of file platform/emlib/inc/em_leuart.h

LEUART_IntGetEnabled#

uint32_t LEUART_IntGetEnabled (LEUART_TypeDef * leuart)

Get enabled and pending LEUART interrupt flags.

Parameters
[in]leuart

Pointer to LEUART peripheral register block.

Useful for handling more interrupt sources in the same interrupt handler.

Note

  • Interrupt flags are not cleared by the use of this function.

Returns

  • Pending and enabled LEUART interrupt sources. The return value is the bitwise AND combination of

    • the OR combination of enabled interrupt sources in LEUARTx_IEN_nnn register (LEUARTx_IEN_nnn) and

    • the OR combination of valid interrupt flags of LEUART module (LEUARTx_IF_nnn).


Definition at line 232 of file platform/emlib/inc/em_leuart.h

LEUART_IntSet#

void LEUART_IntSet (LEUART_TypeDef * leuart, uint32_t flags)

Set one or more pending LEUART interrupts from SW.

Parameters
[in]leuart

Pointer to LEUART peripheral register block.

[in]flags

LEUART interrupt sources to set to pending. Use a bitwise logic OR combination of valid interrupt flags for LEUART module (LEUART_IF_nnn).


Definition at line 255 of file platform/emlib/inc/em_leuart.h

LEUART_StatusGet#

uint32_t LEUART_StatusGet (LEUART_TypeDef * leuart)

Get LEUART STATUS register.

Parameters
[in]leuart

Pointer to LEUART peripheral register block.

Returns

  • STATUS register value.


Definition at line 271 of file platform/emlib/inc/em_leuart.h

LEUART_Reset#

void LEUART_Reset (LEUART_TypeDef * leuart)

Reset LEUART to the same state that it was in after a hardware reset.

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.


Definition at line 475 of file platform/emlib/src/em_leuart.c

LEUART_Rx#

uint8_t LEUART_Rx (LEUART_TypeDef * leuart)

Receive one 8 bit frame, (or part of 9 bit frame).

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

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

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

Note

  • This function will stall if the buffer is empty until data is received.

Returns

  • Data received.


Definition at line 525 of file platform/emlib/src/em_leuart.c

LEUART_RxExt#

uint16_t LEUART_RxExt (LEUART_TypeDef * leuart)

Receive one 8-9 bit frame with extended information.

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

This function is normally used to receive one frame and additional RX status information is required.

Note

  • This function will stall if buffer is empty until data is received.

Returns

  • Data received.


Definition at line 550 of file platform/emlib/src/em_leuart.c

LEUART_Tx#

void LEUART_Tx (LEUART_TypeDef * leuart, uint8_t data)

Transmit one frame.

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

[in]data

Data to transmit. See details above for more info.

Depending on the frame length configuration, 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 the CTRL register, BIT8DV field. See LEUART_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 a part of the specified frame bit length.

Note

  • This function will stall if buffer is full until the buffer becomes available.


Definition at line 581 of file platform/emlib/src/em_leuart.c

LEUART_TxExt#

void LEUART_TxExt (LEUART_TypeDef * leuart, uint16_t data)

Transmit one 8-9 bit frame with extended control.

Parameters
[in]leuart

A pointer to the LEUART peripheral register block.

[in]data

Data to transmit with extended control. Least significant bit contains frame bits and additional control bits are available as documented in the reference manual (set to 0 if not used).

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

Note

  • This function will stall if the buffer is full until the buffer becomes available.


Definition at line 612 of file platform/emlib/src/em_leuart.c

LEUART_RxDataGet#

uint8_t LEUART_RxDataGet (LEUART_TypeDef * leuart)

Receive one 8 bit frame, (or part of a 9 bit frame).

Parameters
[in]leuart

Pointer to LEUART peripheral register block.

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

Note

  • Since this function does not check if 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 LEUART_Rx() is normally a better choice if the validity of the RXDATA register is not certain.

  • Notice that possible parity/stop bits are not considered part of specified frame bit length.

Returns

  • Data received.


Definition at line 310 of file platform/emlib/inc/em_leuart.h

LEUART_RxDataXGet#

uint16_t LEUART_RxDataXGet (LEUART_TypeDef * leuart)

Receive one 8-9 bit frame, with extended information.

Parameters
[in]leuart

Pointer to LEUART peripheral register block.

Used to quickly receive one 8-9 bit frame with extended information by reading RXDATAX register directly, without checking STATUS register for RXDATAV flag. This can be useful from RXDATAV interrupt handler, i.e., waiting is superfluous, in order to quickly read received data.

Note

  • Since this function does not check if 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 LEUART_RxExt() is normally a better choice if the validity of the RXDATAX register is not certain.

  • Notice that possible parity/stop bits are not considered part of specified frame bit length.

Returns

  • Data received.


Definition at line 343 of file platform/emlib/inc/em_leuart.h

Macro Definition Documentation#

LEUART_INIT_DEFAULT#

#define LEUART_INIT_DEFAULT
Value:
{ \
leuartEnable, /* Enable RX/TX when initialization completed. */ \
0, /* Use current configured reference clock for configuring baud rate.*/ \
9600, /* 9600 bits/s. */ \
leuartDatabits8, /* 8 data bits. */ \
leuartNoParity, /* No parity. */ \
leuartStopbits1 /* 1 stop bit. */ \
}

Default configuration for LEUART initialization structure.


Definition at line 116 of file platform/emlib/inc/em_leuart.h