Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Serial port abstraction layer API nrf_serial_read() timeout/data-size issues with a UART sensor

Hi all,

I'm working with NRF52DK using Segger Embedded Studio with NRF SDK 15.0 trying to communicate to a UART sensor using the serial port abstraction layer API. Following the serial_port example and various threads on this forum, I've managed to establish a communication link between the DK and the sensor; however, I ran into 2 issues:

1. I'm using the serial port abstraction layer methods with the instance being set to the IRQ mode. If I set the "timeout in ms" parameter within nrf_serial_read() to "NULL", then what seems to happen is that my sensor isn't replying fast enough after I write to it using nrf_serial_write() (again, with "NULL" passed to nrf_serial_write() for the timeout parameter). That leads to me getting the NRF_ERROR_TIMEOUT from the nrf_serial_read() since it expects there to be data to be read when the program gets to it but there is none. Now, if I do set the timeout parameter to, say, 1000 ms, then the data transmission succeeds; however, as I've read in the documentation,  that may lead to a deadlock. What can I do in this case?

2. How can I establish the data size to be read if I don't know it in advance? As an example, depending on what the sensor reads, it can transmit either an ACK or a NACK with an error code, each having a different payload size. If I declare a size to be read larger than the actual transmission happens to be, then I get the NRF_ERROR_TIMEOUT again. From my understanding, there are no ways around it other than to handle this in the RX event handler? What is the best way to handle it inside the handler? Is it possible to just timeout from the function and move on, without running into the possible deadlock issue?

3. This is not an issue, but I'm not completely clear on whether the queues are cleared after RX/TX. If they are not automatically cleared, how do I clear them and make sure I don't overflow them?

Thank you so much in advance!

Related