Latency of Serial.println() with Arduino UNO

As a part of my current experiment, I’m running following piece of code:

   if (digitalRead(pinDeviceReadReady) == HIGH) {
    Serial.println("DATA READY");
    spiSend(0x20); // command "read request"
    readBuffer.deviceId = spiReceive();
    readBuffer.wireId = spiReceive();
    readBuffer.length = spiReceive();
    for (int i = 0; i <= readBuffer.length; ++i) {[i] = spiReceive();


inline void spiSend(uint8_t data)
  // wait for device ready to write
  while (digitalRead(pinDeviceWriteReady) == LOW);

inline uint8_t spiReceive()
  while (digitalRead(pinDeviceReadReady) == LOW);
  uint8_t data = SPI.transfer(0);
  return data;

The picture below shows the “pinDeviceReadReady (DATA_READY)” indicator value (red) and SPI clock (blue).  There are significant delays after DATA READY indicator is up until the UNO executes SPI transfer.


This is due to Serial.println() debug prints inserted between SPI transfers.  I’ve not read the Serial.println() implementation, but the delay looks to be ranging from 100 to 150 micro seconds.

The large delay disappeared when I removed the Serial.println() lines.


However, you still see delay when you close up a little more.


This is possibly caused by digitalRead() for the indicator or invoking SPI.transfer().  I don’t have to remove this delay for this experiment, but may need to do so later.  The delay is about 3 micro seconds.

2 thoughts on “Latency of Serial.println() with Arduino UNO

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.