Hi,
What is the best way to read the async data received on a UART in to a buffer when ever there is an a byte available and in a separate task read the data from the buffer as and when needed.
reards
KK
Hi,
What is the best way to read the async data received on a UART in to a buffer when ever there is an a byte available and in a separate task read the data from the buffer as and when needed.
reards
KK
Hi,
For receiving uart data byte-for-byte, you can set up your project similar to this:
https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/uart/src/main.c
But, I would recommend that you do as little processing as possible in the UART interrupt handler, by for instance passing the data to a FIFO or using a system workqueue, or which ever other method you prefer.
If you require more advance uart handling (with RX timeouts, specific sizes, etc), I would recommend that you look into the uart_async module. There's a test-program for it here, which includes several uses of it:
Kind regards,
Håkon
Hi Hakon,
Mean while i have figured it out the way you suggested in your first link, but i am ring_buf_put() to collect byte by byte in ISR call back and in task i use ring_buf_get() to get the data when ever needed, i hope ring_buf_put() is not bulky to use in ISR?
regards
KK
Hi KK,
That should be fine. The documentation even lists uart reception as one of the main use-cases:
https://docs.zephyrproject.org/latest/reference/kernel/other/ring_buffers.html
Kind regards,
Håkon