delayMicroseconds() bug

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!

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.

Tom

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

Tom

Good point. I added a warning to the reference:
http://www.arduino.cc/en/Reference/DelayMicroseconds