Page 1 of 1

UART eats my 15th char!

Posted: Sat Oct 05, 2019 5:59 pm
by jakub st
Hi! I'm New here, so hello to everybody!

I'm trying to read data from GPS module (GY-GPSV3-NEO). As you probably know it communicates via UART.
So first I tied to simulate any UART communication and catch some words.

I found and modified this code:

Code: Select all

	uos.dupterm(None, 1)
	uart = UART(0, 115200)
	ch = b""
	while ch != b"quit":
		if uart.any():
			ch = uart.read()
 			uart.write(ch)
	uos.dupterm(UART(0, 115200), 1)
	
and every time I send a string longer than 15 character it "eats" the 15th character. I don't know how exactly describe it.
hm..
I send "01234567890123456789"
And as answer I get the string without second five, so it is: "012346789012346789"
I've tried with

Code: Select all

uart.readinto(buf)
with buf declaration, or

Code: Select all

ch = uart.readline()
and always the same.
Where do I fail? Where is the problem?

Re: UART eats my 15th char!

Posted: Sat Oct 05, 2019 6:28 pm
by Roberthh
You do not fail. By default, the receive buffer has a size of 16. Due to the way it is implemented, the 16th character is lost. There was already discussion bout that, and that it should be fixed. You may avoid that problem by increasing the receive buffer with the keyword argument rxbuf=nnn, e.g.

uart = UART(0, 115200, rxbuf=256)

Re: UART eats my 15th char!

Posted: Wed Jul 28, 2021 11:43 pm
by Trikkitt
Looks like this is still a significant bug. I've just wasted a day trying to figure out what is going on with my code. Turns out its a bug in Micropython that looks to have been introduced since I last updated (must be 3 years ago the version I had been using). Very frustrating - please just as a temporary fix change the default buffer size to 16 so that the default behaviour isn't to drop every 16th character received.

Re: UART eats my 15th char!

Posted: Thu Mar 24, 2022 2:10 am
by Trikkitt
Well this appears to have got worse. I'm using 1.18 and now no matter what buffer size I try and use I lose the 16th digit. I'm also seeing random other character drops on serial receive. This is driving me nuts! To the point that might have to drop the use of micropython if it can't do something as simple as receive serial data. So frustrating. Any suggestions on what I can do to work around this issue?

Re: UART eats my 15th char!

Posted: Thu Mar 24, 2022 6:39 am
by Roberthh
How do youu set up UART?

Re: UART eats my 15th char!

Posted: Thu Mar 24, 2022 9:14 am
by Trikkitt
Roberthh wrote:
Thu Mar 24, 2022 6:39 am
How do youu set up UART?
I've tried a few different method. I've tried it with just specifying the timeout value to 1000, setting the character time out to 1000, trying timeout figures of 20 and 2, trying the rxbuf set to 15,16, 100 and 256. All resulted 16th digit loss, or total data loss from the 16th digit seemingly at random, I couldn't tell why i'd see one result over the other.