Serial Port losing 16th digit
Posted: Wed Jul 28, 2021 11:33 pm
I'm running the latest 1.16 version of Micropython on an ESP8266. I'm capturing the serial port away from REPL and directing it to my code. This code is something I wrote a few years ago that should just work, but I have change the version of Micropython so while I can't rule out my code it does look suspiciously like a Micropython issue. For some reason the 16th character being read from the serial port goes missing!
Diags: I've connected a serial port from my PC to the serial port receive of the ESP8266 so I can see what data it is actually receiving, and I can see the string arrive perfectly formed. It is just some text (in this case a hex string). I tried lowering the connection speed from 115200 to 38400 in case something was going wrong with the framing, but this made no difference. I tried changing the onward delivery format in case there was something at the network end that cause it, but still the same digit is missing. I tried changing the uart.read command to specify only 5 digits and concatenate them together, but unfortunately that didn't change the results.
The following is a slimmed down piece of the code:
uart = UART(0,38400)
uart.init(38400, bits=8, parity=None, stop=1, timeout=1)
serveraddr = usocket.getaddrinfo(servername,40001,0, usocket.SOCK_STREAM)[0][-1]
s=usocket.socket()
s.connect(serveraddr)
while True:
if (uart.any()>0):
serbuf=uart.read()
s.setblocking(True)
s.write(serbuf)
s.setblocked(false)
The serial data arrives minus the 16th digit over my TCP connection. With larger amounts of data every 16th digit is missing.
Am I doing something wrong? Or is there an issue with this version of Micropython?
Diags: I've connected a serial port from my PC to the serial port receive of the ESP8266 so I can see what data it is actually receiving, and I can see the string arrive perfectly formed. It is just some text (in this case a hex string). I tried lowering the connection speed from 115200 to 38400 in case something was going wrong with the framing, but this made no difference. I tried changing the onward delivery format in case there was something at the network end that cause it, but still the same digit is missing. I tried changing the uart.read command to specify only 5 digits and concatenate them together, but unfortunately that didn't change the results.
The following is a slimmed down piece of the code:
uart = UART(0,38400)
uart.init(38400, bits=8, parity=None, stop=1, timeout=1)
serveraddr = usocket.getaddrinfo(servername,40001,0, usocket.SOCK_STREAM)[0][-1]
s=usocket.socket()
s.connect(serveraddr)
while True:
if (uart.any()>0):
serbuf=uart.read()
s.setblocking(True)
s.write(serbuf)
s.setblocked(false)
The serial data arrives minus the 16th digit over my TCP connection. With larger amounts of data every 16th digit is missing.
Am I doing something wrong? Or is there an issue with this version of Micropython?