UART read losing bytes
Posted: Mon Oct 03, 2022 11:16 am
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.
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.