Skip to content

UART

A universal asynchronous receiver-transmitter (UART) is a peripheral device for asynchronous serial communication.

The UART API supports one UART on all MCUs, except nRF52840 where UARTE1 (UART ID=1) also can be used, but only for output.

Defines

MIRA_IODEF_UART0

#define MIRA_IODEF_UART0

MIRA_IODEF_UART1

#define MIRA_IODEF_UART1

MIRA_IODEF_UART2

#define MIRA_IODEF_UART2

MIRA_IODEF_UART

#define MIRA_IODEF_UART(_ID)

Types

mira_uart_input_callback_t

typedef int(* mira_uart_input_callback_t) (uint8_t c, void *storage);

Enums

mira_uart_parity_t

Name Description
MIRA_UART_PARITY_NONE
MIRA_UART_PARITY_EVEN
MIRA_UART_PARITY_ODD

Structs

mira_uart_config_t

Name Type Description
baudrate int32_t
tx_pin mira_gpio_pin_t Pin to use as TXD
rx_pin mira_gpio_pin_t Pin to use as RXD
parity mira_uart_parity_t Please note: Parity is not yet supported

Functions

mira_uart_init

mira_status_t mira_uart_init(uint8_t uart_id, const mira_uart_config_t *config);

Initialize a UART module.

The custom config is passed as a parameter (NULL for platform default).

Note

this might start a higher resolution clock in the CPU, which can significantly increase the power consumption until CPU is restarted. For UART 1 is only available on nRF52833 and nRF62840 MCUs and there only for TX.

Parameters

Name Description
uart_id The index of the UART peripheral.
config Pointer to a configuration to setup.

Return value

Name Description
MIRA_SUCCESS UART was successfully initialized.
MIRA_UART_ERROR_INIT UART could not initialize.
MIRA_ERROR_NOT_SUPPORTED Invalid UART id.

mira_uart_set_input_callback

mira_status_t mira_uart_set_input_callback(uint8_t uart_id, mira_uart_input_callback_t cb, void *storage);

Set a callback to be called on uart byte input.

Parameters

Name Description
uart_id The index of the UART peripheral.
cb The callback to call.
storage Storage pointer which is used to store optional information to be used by the callback function. E.g. it could be used as an identifier or to pass on a configuration struct.

Return value

Name Description
MIRA_SUCCESS The callback was successfully set.
Back to top