Page 1 of 3

\xFF is missing from UART.read()

Posted: Mon Aug 08, 2022 2:55 pm
by garudaone
Hi,
I send data from a LORA RS485 via UART to another. All the 0xFF byte are missing. At first, I thought it maybe the LORA Module have problem, I try another pair from a different company. Exactly same result
For example:

Code: Select all

uart.write(b'\xff\xff\x01\x02')
On the receiver will receive as:

Code: Select all

b'\x01\x02'
Any suggestion?

Thanks;

Re: \xFF is missing from UART.read()

Posted: Mon Aug 08, 2022 6:02 pm
by karfas
You dont't tell us anything about your circuits. Is the receiving UART controlled from micropython or not ? Is the RS485 receiver always on or do you poll different devices on the bus ? Are terminator resistors in place on the RS485 bus ?

RS485 timing can be tricky. To rule out a general micropython problem, you should run a quick loopback test using the UART only.

Re: \xFF is missing from UART.read()

Posted: Tue Aug 09, 2022 2:36 am
by garudaone
karfas wrote:
Mon Aug 08, 2022 6:02 pm
You dont't tell us anything about your circuits. Is the receiving UART controlled from micropython or not ? Is the RS485 receiver always on or do you poll different devices on the bus ? Are terminator resistors in place on the RS485 bus ?

RS485 timing can be tricky. To rule out a general micropython problem, you should run a quick loopback test using the UART only.
Both side are micropython controller(a9 gprs). I sent out 900 packets of 50 bytes each. 36 bytes missing in total and all those bytes are \xff and I try to send manually using REPL, it's the same(all \xFF) are missing so I rule out wiring or circuit issue. I also try to sent from one side as A9 GPRS to the receiver connecting with computer, this one work fine.

Thus my rough guess is that this \xFF mean something that is why it's removed.

Re: \xFF is missing from UART.read()

Posted: Tue Aug 09, 2022 5:21 am
by TheSilverBullet
Hmmm, working here…

On the PC side:

Code: Select all

~$ stty -F /dev/ttyUSB0 raw 9600
~$ hd -v < /dev/ttyUSB0 
On the MicroPython (1.19.1 / rp2040) side:

Code: Select all

>>> u = machine.UART(0)
>>> u.init(9600,txbuf=1024)
>>> u
UART(0, baudrate=9600, bits=8, parity=None, stop=1, tx=0, rx=1, txbuf=1024, rxbuf=256, timeout=0, timeout_char=2, invert=None)

>>> ba = bytearray(256)
>>> for i in range(256):
...     ba[i] = i
... 
>>> u.write(ba)
256
Here's what's displayed:

Code: Select all

00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000080  80 81 82 83 84 85 86 87  88 89 8a 8b 8c 8d 8e 8f  |................|
00000090  90 91 92 93 94 95 96 97  98 99 9a 9b 9c 9d 9e 9f  |................|
000000a0  a0 a1 a2 a3 a4 a5 a6 a7  a8 a9 aa ab ac ad ae af  |................|
000000b0  b0 b1 b2 b3 b4 b5 b6 b7  b8 b9 ba bb bc bd be bf  |................|
000000c0  c0 c1 c2 c3 c4 c5 c6 c7  c8 c9 ca cb cc cd ce cf  |................|
000000d0  d0 d1 d2 d3 d4 d5 d6 d7  d8 d9 da db dc dd de df  |................|
000000e0  e0 e1 e2 e3 e4 e5 e6 e7  e8 e9 ea eb ec ed ee ef  |................|
000000f0  f0 f1 f2 f3 f4 f5 f6 f7  f8 f9 fa fb fc fd fe ff  |................|

Re: \xFF is missing from UART.read()

Posted: Tue Aug 09, 2022 7:16 am
by garudaone
TheSilverBullet wrote:
Tue Aug 09, 2022 5:21 am
Hmmm, working here…

On the PC side:

Code: Select all

~$ stty -F /dev/ttyUSB0 raw 9600
~$ hd -v < /dev/ttyUSB0 
On the MicroPython (1.19.1 / rp2040) side:

Code: Select all

>>> u = machine.UART(0)
>>> u.init(9600,txbuf=1024)
>>> u
UART(0, baudrate=9600, bits=8, parity=None, stop=1, tx=0, rx=1, txbuf=1024, rxbuf=256, timeout=0, timeout_char=2, invert=None)

>>> ba = bytearray(256)
>>> for i in range(256):
...     ba[i] = i
... 
>>> u.write(ba)
256
Here's what's displayed:

Code: Select all

00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000080  80 81 82 83 84 85 86 87  88 89 8a 8b 8c 8d 8e 8f  |................|
00000090  90 91 92 93 94 95 96 97  98 99 9a 9b 9c 9d 9e 9f  |................|
000000a0  a0 a1 a2 a3 a4 a5 a6 a7  a8 a9 aa ab ac ad ae af  |................|
000000b0  b0 b1 b2 b3 b4 b5 b6 b7  b8 b9 ba bb bc bd be bf  |................|
000000c0  c0 c1 c2 c3 c4 c5 c6 c7  c8 c9 ca cb cc cd ce cf  |................|
000000d0  d0 d1 d2 d3 d4 d5 d6 d7  d8 d9 da db dc dd de df  |................|
000000e0  e0 e1 e2 e3 e4 e5 e6 e7  e8 e9 ea eb ec ed ee ef  |................|
000000f0  f0 f1 f2 f3 f4 f5 f6 f7  f8 f9 fa fb fc fd fe ff  |................|
For me, the PC side is ok(PC can receive all ff). My receiving board is A9 GPRS and it has problem with \xff.

Re: \xFF is missing from UART.read()

Posted: Tue Aug 09, 2022 8:47 am
by TheSilverBullet
garudaone wrote:
Tue Aug 09, 2022 7:16 am
For me, the PC side is ok(PC can receive all ff). My receiving board is A9 GPRS and it has problem with \xff.
Tried receiving data (PC to rp2040), works as expected.

Code: Select all

>>> u = machine.UART(0)
>>> u.init(9600,txbuf=1024)
>>> u.read()
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'
So it might be a problem with the ›A9 GPRS‹ whatever that may be, or with the MicroPython implementation for that particular board .

Re: \xFF is missing from UART.read()

Posted: Tue Aug 09, 2022 9:58 am
by garudaone
TheSilverBullet wrote:
Tue Aug 09, 2022 8:47 am
garudaone wrote:
Tue Aug 09, 2022 7:16 am
For me, the PC side is ok(PC can receive all ff). My receiving board is A9 GPRS and it has problem with \xff.
Tried receiving data (PC to rp2040), works as expected.

Code: Select all

>>> u = machine.UART(0)
>>> u.init(9600,txbuf=1024)
>>> u.read()
b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'
So it might be a problem with the ›A9 GPRS‹ whatever that may be, or with the MicroPython implementation for that particular board .
I think you are right. I put the board to sleep and call uart.read() after the sender finish sending data. all \xff are received. However, other bytes are missing.

Re: \xFF is missing from UART.read()

Posted: Tue Aug 09, 2022 10:08 am
by Roberthh
Could it be that \xff is some kind of special character, that has to be escaped? What happens if you send \xff twice?

Re: \xFF is missing from UART.read()

Posted: Tue Aug 09, 2022 11:11 am
by garudaone
Roberthh wrote:
Tue Aug 09, 2022 10:08 am
Could it be that \xff is some kind of special character, that has to be escaped? What happens if you send \xff twice?
still removed from the receiving data.

Re: \xFF is missing from UART.read()

Posted: Tue Aug 09, 2022 2:49 pm
by karfas
garudaone wrote:
Tue Aug 09, 2022 9:58 am
I put the board to sleep and call uart.read() after the sender finish sending data. all \xff are received. However, other bytes are missing.
So there seems to be no problem at all receiving 0xff. For me, this smells like some kind of handshake or timing problem.
This is hard to analyze from the distance, especially when we need to guess how exactly your boards are connected, which software (e.g. micropython version) runs, ...