uasyncio StreamReader uart problem.

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

uasyncio StreamReader uart problem.

Post by prem111 » Wed Nov 18, 2020 8:05 pm

Hi. How to solve simultaneous get data from UART, and a task in another async function. I have a problem because when another function that is quite heavy on the system is looping etc, the data from the UART is truncated. I am using one StreamWriter. Thanks.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: uasyncio StreamReader uart problem.

Post by pythoncoder » Thu Nov 19, 2020 7:50 am

You haven't given us much to go on here. What hardware are you using? The following is based on my impression of what may be going on in your code.

If you have coroutines which block for significant periods of time it is possible for the UART receive buffer to overrun. Currently uasyncio services I/O in round-robin fashion with the other tasks. This is not ideal and improvements are planned.

If you are losing received data options are:
  • Reduce the worst-case blocking times in your tasks to increase the UART polling frequency.
  • Increase the UART receive buffer size (a constructor option on some platforms).
  • Reduce baud rate.
  • Implement RTS/CTS UART flow control (supported in hardware on some platforms).
  • Implement software flow control in code (XON/XOFF or other).
Peter Hinch
Index to my micropython libraries.

prem111
Posts: 127
Joined: Sun Feb 23, 2020 3:18 pm

Re: uasyncio StreamReader uart problem.

Post by prem111 » Thu Nov 19, 2020 10:25 am

Ok. Reduce worst-case blocking times it helped. Thanks for the explanation.

Post Reply