pulkin / micropython

MicroPython implementation on Ai-Thinker GPRS module A9 (RDA8955)
https://micropython.org
MIT License
103 stars 30 forks source link

UART issue #115

Closed garudaonekh closed 1 year ago

garudaonekh commented 1 year ago

Hi, I use UART 1(GPS Uart) to communicate with RS485 Modbus. It works fine on REPL(Run the code line by line)

But in main.py, It cannot read data properly(some bytes are missing and some are corrupt) even though I put sleep before reading or use while-loop. uart.any() returns 1. Buffer should not be an issue because the data to read is actually only 9 bytes. Try uasyncio also not help.

In my testing, if I use time.sleep or while loop after writing, the received data will have problem, that's why when I run write and then read in REPL, the received data is fine

here's my init code: uart=UART(1,4800) uart.init(4800, bits=8, parity=None, stop=1)

garudaonekh commented 1 year ago

After my further investigation, another byte is missing when the sensor value increase to 80%+(Humidity sensor). When I increase the baudrate, the number of missing bytes are more. However, I can't decrease it further as the sensor only minimum baudrate is 2400.

When I run code from REPL, I receive 9 bytes. anyhow, the missing one byte is ok. but if it missed two bytes. I can't figure out the real value of the sensor.

Here's the sample: From REPL(The correct one, 9 bytes): b'd\x03\x04\x02\xd9\x01/_:' Normal one(8 bytes): b'd\x04\x02\xd9\x012\x9f3' When the humidity is above 80%(only 7 bytes): b'd\x046\x013n\xfa'

garudaonekh commented 1 year ago

Ok, I found out the reason. All byte with value of 0x03 are missing. This byte correspond to Ctrl+C. I try to disable it as suggested by micropython.kbd_intr(-1) and don't print it out. it's ok now.