We are using esp32 and trying to read 900 characters from the uart at 9600 baud. A typical way to do this is to read one character at a tim e as they arrive in the uart and store it. We seem to need to increase the uart rxbuffer size to at least 900 for this to work reliably. Example is below:
Code: Select all
while True:
if port.any():
x = port.read(1)
xstr = x.decode('utf-8')
if xstr == "\n":
break
response += xstr
I would think that each port.read(1) call would clear 1 character from the uart rxbuffer FIFO and we should be able to reliably read in characters continuously and for much longer than the rxbuf length as long as we do it fast enough. This doesn't appear to be the case with esp32. In one test with a 917 character message, we receive the first 360 characters, and the last 41, but are missing everything in between, using the default uart.init() call, which for the esp32 has default rxbuf=256. If we call uart.init(.... rxbuf=1024) it all works reliably. Is there something we are doing wrong here?