nRF5 SDK v14.2.0
Serial port library

This module allows to create and handle serial port instances. It is designed as a more sophisticated replacement for the app_uart module. The following are the advantages of this module over app_uart:

You can initialize this module in one of the three available modes:

The following code snippet shows how to create a configuration structure for each of these modes:

NULL, NULL, NULL, NULL);
&queues, &buffers, NULL, NULL);
&queues, &buffers, NULL, NULL);

Such configuration structure can be passed directly to the nrf_serial_init method. The table below shows the configuration dependencies:

Mode/Configuration QUEUES BUFFERS EVENT_HANDLER SLEEP_HANDLER
NRF_SERIAL_MODE_POLLING U U U U
NRF_SERIAL_MODE_IRQ R R O O
NRF_SERIAL_MODE_DMA R R O O

In Interrupt and DMA modes, you must create the RX/TX queues. The following code snippet shows how to create an instance of the RX/TX queue:

#define SERIAL_FIFO_TX_SIZE 32
#define SERIAL_FIFO_RX_SIZE 32
NRF_SERIAL_QUEUES_DEF(serial_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);

Interrupt and DMA modes require a definition of the transfer buffers. They are the smallest slices of data that can be transfered in a single UART driver driver request. The following code snippet shows how to declare transfer buffers:

#define SERIAL_BUFF_TX_SIZE 1
#define SERIAL_BUFF_RX_SIZE 1
NRF_SERIAL_BUFFERS_DEF(serial_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);

For API documentation of this library, refer to Serial port abstraction layer.

For a usage example, refer to Serial Port Library Example.


Documentation feedback | Developer Zone | Subscribe | Updated