Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

uart.read() takes one second to execute?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

uart.read() takes one second to execute?

by ramsh on Thu Sep 10, 2020 5:17 am

Hello,

Using two Feathers STM32F405 connected by RX/TX both running:
Code: Select all | TOGGLE FULL SIZE
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 | TOGGLE FULL SIZE
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

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

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

by westfw on Thu Sep 10, 2020 6:38 am

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.)

westfw
 
Posts: 1717
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

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

by jerryn on Thu Sep 10, 2020 6:51 am


jerryn
 
Posts: 1291
Joined: Sat Sep 14, 2013 9:05 am

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

by ramsh on Thu Sep 10, 2020 7:44 am

Thank you all for your valuable feedback!

I've updated my code and it works as needed:
Code: Select all | TOGGLE FULL SIZE
uart = busio.UART(board.TX, board.RX, baudrate=115200, timeout=0.01)


Many thanks to this great community!!!

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

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

by kevinjwalters on Thu Sep 10, 2020 11:19 am

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.

kevinjwalters
 
Posts: 735
Joined: Sun Oct 01, 2017 3:15 pm

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

by ramsh on Thu Sep 10, 2020 4:24 pm

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!

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

Please be positive and constructive with your questions and comments.