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¶
MIRA_IODEF_UART1¶
MIRA_IODEF_UART2¶
MIRA_IODEF_UART¶
Types¶
mira_uart_input_callback_t¶
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¶
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. UART 1 is only available on nRF52840 MCUs and 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_deinit¶
Deinitialize a UART module.
Parameters¶
Name | Description |
---|---|
uart_id | The index of the UART peripheral. |
Return value¶
Name | Description |
---|---|
MIRA_SUCCESS | UART was successfully deinitialized. |
MIRA_UART_ERROR_INIT | UART could not be deinitialized. |
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. |
MIRA_ERROR_NOT_SUPPORTED | Invalid UART id. |