Page 1 of 1

UART read losing bytes

Posted: Mon Oct 03, 2022 11:16 am
by technomage
Hello,
I am writing a code on an Olimex ESP32 Gateway that sends a command to a board and receives data from the board through rs485 with a baudrate of 115200 * 100.
The data received is about 3 kB foreach command. After sending the command, the code delays 3.5ms (enough for the whole 3kB arrive). And then I read with uart_read_bytes() with a timeout of 0 in smaller chunks (250 bytes). I have set the TOUT feature enabled with a tout of 19.

The problem is that in some random transmissions I read some random number of bytes less than the expected. I connected a logic analyzer on the receive GPIO pins and all the data expected is transmitted over the wire. Also I check the number of bytes in the input buffer after the delay (with uart_get_buffered_data_len()) and in the bad transmissions the number of bytes in the buffer is less than the expected.

I tried to increment the delay and the same happens. If I decrement, increment or disable the TOUT, the number bad transmissions is higher.

Do somebody have an idea of what is happening here?

Thanks.

Re: UART read losing bytes

Posted: Wed Oct 05, 2022 1:43 pm
by Craige Hales
115200 * 100
- if that means 11,520,000, which would be about 1MByte per second, that's a really high baud rate. My quick research on RS485 says the flow control is not done with RTS/CTS, but uses software (xon/xoff?). I'd guess there is an occasional buffer overrun, causing dropped characters. I didn't see anyone suggesting >5,000,000 would work, and even those came with caveats.
in the bad transmissions the number of bytes in the buffer is less than the expected
- I think that means the current problem is NOT in the code you wrote to read the buffer.