3 months, 1 week ago.

how to reliably read from UART

Hi, I am trying to read a serial datastream at 115200 baud. this does work with my code, but sometimes (about 1 of 1000bytes) 1 byte is received incorrectly. I am receiving with UARTSerial and sending the received stuff out over BLE in paralell.

I have confirmed no buffer is overflowing (except for the hardware buffer... but I dont think so..) I am on an NRF52840.

Is there anything I am missing in order to make it more reliable? Do I have to split receiving and sending into seperate threads maybe? would that help? also I have the feeling, that the problem gets worse, with more CPU load.

what can I do about this?

- Jonas

Comment on this question

1 Answer

3 months ago.

Hi Jonas,

I would need more information for clarifying this issue.

Where's the error byte occurring? Is it on UART receive side or on BLE receive side?

Have you checked readble() before read()?

For increasing CPU load, maybe you can use a smaller connection interval and no slave latency, under this configuration, would it be easier for reproducing this issue?

In you current implementation, where do you put UART receiving, is it in ISR or main thread?



Hi, thanks for the answer. the Error byte is occuring on the UART receiving side, and way before it reaches user code. I debugged far into the MBED code and everywhere I did, I saw the wrong bytes. they occur at random times, not predictable. no, I didnt check readable, from my point of view, If there are bytes in the buffer, I should get valid readings. But I will read into this. I already have 8ms conn Interval and 0 slave latency, in order to achieve maximum throughput.

the library receives uart by ISR, then I will get an SIGIO event and from there forward control to the main thread and read from there. EDIT:just tried with readable, nothing changed.

posted by Jonas Woerner 20 May 2019

You need to log in to post a question