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:
- API is more generic and robust: you can read or write any amount of bytes.
- Multi-instance capability.
- The module can work in three modes: POLLING, IRQ, and DMA.
- Calls can be asynchronous and synchronus (with timeouts).
- Independent RX/TX FIFOs with configurable sizes.
- Configurable RX/TX transfer buffers (smallest transfer slice).
- Event handler (not mandatory).
- Sleep handler (not mandatory).
You can initialize this module in one of the three available modes:
-
NRF_SERIAL_MODE_POLLING - Simple polling operation without any interrupts.
- Functional timeouts.
- Only 6-byte size hardware FIFO.
-
NRF_SERIAL_MODE_IRQ - Interrupt mode.
- Software FIFOs with configured size.
- User-defined transfer slice size.
- Funtional timeouts.
- User-defined event and sleep handlers.
- NRF_SERIAL_MODE_DMA - Same functionality as in IRQ mode but uses EasyDMA.
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:
- R - Required
- O - Optional
- U - Unused
| 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 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 .