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;
}
}
...
}
}