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:
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:
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 - legacy layer driver request. The following code snippet shows how to declare transfer buffers:
For API documentation of this library, refer to Serial port abstraction layer.
For a usage example, refer to Serial Port Library Example.