uart.read() takes one second to execute?

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ramsh
 
Posts: 114
Joined: Fri Apr 29, 2016 5:17 am

uart.read() takes one second to execute?

Post by ramsh »

Hello,

Using two Feathers STM32F405 connected by RX/TX both running:

Code: Select all

Adafruit CircuitPython 5.3.1 on 2020-07-13; Feather STM32F405 Express with STM32F405RG
it takes one second for the receiver side that waits and reads the incoming data to execute the uart.read() line:

Code: Select all

while True:
    timeIt = time.monotonic()
    data = uart.read(1)  # read 1 byte
    print(f'>>>>> {data} {time.monotonic() - timeIt}')
and the output:
>>>>> None 1.0
>>>>> None 1.0
>>>>> None 1.0
>>>>> None 1.0
>>>>> None 1.0
>>>>> None 1.0
>>>>> None 1.0
is this normal or (once again) I miss something?
Thanks much in advance!
Ram

User avatar
westfw
 
Posts: 2008
Joined: Fri Apr 27, 2007 1:01 pm

Re: uart.read() takes one second to execute?

Post by westfw »

It would be "common" for a uart read function to "time out" when there is no data.
The similar Arduino Serial.readBytes() function also does this.

(There's probably a different function that is "non-blocking" and returns immediately if there is no data.)

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: uart.read() takes one second to execute?

Post by jerryn »


User avatar
ramsh
 
Posts: 114
Joined: Fri Apr 29, 2016 5:17 am

Re: uart.read() takes one second to execute?

Post by ramsh »

Thank you all for your valuable feedback!

I've updated my code and it works as needed:

Code: Select all

uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=0.01)
Many thanks to this great community!!!

User avatar
kevinjwalters
 
Posts: 1025
Joined: Sun Oct 01, 2017 3:15 pm

Re: uart.read() takes one second to execute?

Post by kevinjwalters »

Depending on what you're ultimately going to be doing with it uart.in_waiting (mentioned in the docs @jerryn cited) may be useful too.

User avatar
ramsh
 
Posts: 114
Joined: Fri Apr 29, 2016 5:17 am

Re: uart.read() takes one second to execute?

Post by ramsh »

kevinjwalters wrote:Depending on what you're ultimately going to be doing with it uart.in_waiting (mentioned in the docs @jerryn cited) may be useful too.
good tip, much appreciated!

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”