I m trying to receive a byte from Atmega2560 at an unexpected time ( using USART ) on my pc. So how do I ensure that i don't miss the byte in my python code ( which has may functions running)
Asked
Active
Viewed 55 times
-1
-
As @DavidGrayson's answer mentions, a real OS will buffer the data from the serial device. What you read from a serial terminal depends on (a) when was the data sent (and received), (b) when was the serial terminal opened, and (c) when was the receive buffer flushed. Simple answer: (b) and (c) must occur before (a). The data will be available for reading by your program unless the receive buffer overflows (but it's the newest data that is lost). – sawdust Feb 04 '19 at 23:11
1 Answers
1
You didn't say what operating system you are using or how the ATmega2560 is connected to the computer, but the drivers in your operating system responsible for receiving the serial data from the ATmega2560 will almost certainly have a buffer for holding incoming bytes, so you don't need to worry about constantly reading from the serial port in your Python program. Just read when you get around to it, and the byte should be waiting for you in the buffer.
It's easy to test that this is the case: send a byte from the AVR, purposely wait a few seconds, then read the byte and make sure it was received correctly.

David Grayson
- 84,103
- 24
- 152
- 189