I am trying to use UART with interrupts and fifo, by using nRF52 SDK 12.2.0 example. It works until the first overflow, after which I cannot any more receive characacters. The related code from SDK is:
case NRF_DRV_UART_EVT_RX_DONE:
// Write received byte to FIFO.
err_code = app_fifo_put(&m_rx_fifo, p_event->data.rxtx.p_data[0]);
if (err_code != NRF_SUCCESS)
{
app_uart_event.evt_type = APP_UART_FIFO_ERROR;
app_uart_event.data.error_code = err_code;
m_event_handler(&app_uart_event);
}
// Notify that there are data available.
else if (FIFO_LENGTH(m_rx_fifo) != 0)
{
app_uart_event.evt_type = APP_UART_DATA_READY;
m_event_handler(&app_uart_event);
}
// Start new RX if size in buffer.
if (FIFO_LENGTH(m_rx_fifo) <= m_rx_fifo.buf_size_mask)
{
(void)nrf_drv_uart_rx(&app_uart_inst, rx_buffer, 1);
}
else
{
// Overflow in RX FIFO.
debugln("rx!");
m_rx_ovf = true;
// AFTER THAT, NO MORE CHARACTERS ARE RECEIVED!
}
break;
How could I recover the UART receiver from the situation? EDIT: The same seems too happen also without any overflow. Then the driver hangs on repeating this driver code fragment on every character:
case NRF_DRV_UART_EVT_ERROR:
debug("E");
app_uart_event.evt_type = APP_UART_COMMUNICATION_ERROR;
app_uart_event.data.error_communication = p_event->data.error.error_mask;
(void)nrf_drv_uart_rx(&app_uart_inst, rx_buffer, 1);
m_event_handler(&app_uart_event);
break;
Related question: in the app_uart_fifo there is:
static uint8_t tx_buffer[1];
static uint8_t rx_buffer[1];
On the other hand, there are another buffers made by APP_UART_FIFO_INIT() macro (shown below). The question is how these two (four) buffers are related to each other?
#define APP_UART_FIFO_INIT(P_COMM_PARAMS, RX_BUF_SIZE, TX_BUF_SIZE, EVT_HANDLER, IRQ_PRIO, ERR_CODE) \
do \
{ \
app_uart_buffers_t buffers; \
static uint8_t rx_buf[RX_BUF_SIZE]; \
static uint8_t tx_buf[TX_BUF_SIZE]; \
\
buffers.rx_buf = rx_buf; \
buffers.rx_buf_size = sizeof (rx_buf); \
buffers.tx_buf = tx_buf; \
buffers.tx_buf_size = sizeof (tx_buf); \
ERR_CODE = app_uart_init(P_COMM_PARAMS, &buffers, EVT_HANDLER, IRQ_PRIO); \
} while (0)