Go Down

Topic: delayMicroseconds() bug (Read 2206 times) previous topic - next topic


If you use delayMicroseconds, you risk data loss on the serial line.
For example, if you use the following code, some data sent is not echoed back!

Code: [Select]
char c;

void setup()
   Serial.begin(19200); //init the serial com

void loop()
 while (Serial.available()>0) { //check for data
      Serial.print(Serial.read()); //echo the data
 delayMicroseconds(20000); //delay(20); //pause

If I send a lot of data, very quickly, like the following list, 1 2 3 4 5 6 7 8 9 10 11 12 13,
only some of the characters will be echoed back, for example: 1 2 8 9 10 11 12 13
(numbers 3 to 7 dissappeared, probably because they were being transfered during the pause)

If you use delay() there is no loss of data.

Thomas Ouellet Fredericks


Oh, I see in the source code that interrupts are disabled during delayMicroseconds()
Should be a warning about that!

Thomas Ouellet Fredericks


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131