This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UART reception end

Is there a way to know that there is no more data being received via UART?

One solution is, of course, to start a timer every time a byte is received via uart_evt_handler->APP_UART_DATA so if it expires we know that nothing was received during the timer period, but is there a more elegant solution?

EDIT:

Aryan's solution is viable, but if some reason using the API is not possible, a simple (and obvious in the hindsight) solution is to use a flag:

void foo(void)
{
    ...
    while (byte_received)
    {
        byte_received = false;
        nrf_delay_ms(5);
    }

    // Handle data
}

void uart_evt_handler(app_uart_evt_t *p_app_uart_event)
{
    switch (p_app_uart_event->evt_type)
    {
        case APP_UART_DATA:
        {
            uint8_t byte;
            if (app_uart_get(&byte) == NRF_SUCCESS)
            {
                rx_buffer[rx_buffer_index++] = byte;
                byte_received = true;
            }
        }
        ...
    }
}
Parents
  • Why not just use app_uart_get API? if there is nothing in RX buffer then NRF_ERROR_NOT_FOUND will be returned and the driver will be configured to generate an event on data reception. This seems to be fairly enough functionality needed. We will anyhow wont be able to tell when the other side will send more data or if it is finished. So maybe use timers to timeout if you do not get the receive event within the configured time. Did I miss something in your question?

Reply
  • Why not just use app_uart_get API? if there is nothing in RX buffer then NRF_ERROR_NOT_FOUND will be returned and the driver will be configured to generate an event on data reception. This seems to be fairly enough functionality needed. We will anyhow wont be able to tell when the other side will send more data or if it is finished. So maybe use timers to timeout if you do not get the receive event within the configured time. Did I miss something in your question?

Children
Related