Serial.print()
feeds the data into the TX buffer one character at a time (through the Print
class's inherited .write()
function which HardwareSerial
implements). If there isn't enough room in the TX buffer for the next character it waits for there to be room available.
Characters are removed one at a time from the TX buffer and sent through the physical UART by the UART's TX interrupt.
To put it in more detail:
- When you call
Serial.print()
it's actually calling Print.print()
, because Print
is a parent class of the HardwareSerial
class.
Print.print()
repeatedly calls Print.write()
for each character to print.
Print.write()
is a pure virtual function (which means it's only got the definition in the Print
class and child classes must implement it).
HardwareSerial.write()
implements the Print.write()
function which takes the character and (with possible blocking while waiting for space) adds it to the TX buffer.
Serial
is an instance of the HardwareSerial
class.