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

nRF52840 Zephyr UART Callback

Hello,

Currently I have implemented a UART callback using the CONFIG_UART_ASYNC_API setting as follows:

static char recv_buf[1024];

static bool InitializeUart (void)
{
  uart_dev = device_get_binding("UART_0");

  if (!uart_dev)
    return false;

  uart_callback_set(uart_dev, uart_callback, NULL);
  uart_rx_enable(uart_dev, recv_buf, sizeof(recv_buf), 100);

  return true;
}

static void uart_callback (struct uart_event *evt, void *user_data)
{
  switch (evt->type)
  {
    case UART_RX_RDY:
    {
      printk("%s", recv_buf);
    }
    break;

    case UART_RX_DISABLED:
    {
      uart_rx_enable(uart_dev, recv_buf, sizeof(recv_buf), 100);
    }
    break;

    case UART_RX_STOPPED:
    {
      printk("RX has stopped due to external event.\n");
    }
    break;

    default: 
    break;
  }
}

However, all data that I receive is appended constantly, until the buffer is full.
I would like to empty the buffer every time UART_RX_RDY is received, but I cannot find a function to support this in the UART API documentation. Clearing the buffer myself does not work.

Any hints?

Parents Reply Children
No Data
Related