Description
As I mentioned in the forum post:
SerialX (X=1-4) are unbuffered? surprised
The call to SerialX.flush() does not work as I expected, nor does it comply with the documentation.
https://www.arduino.cc/reference/en/language/functions/communication/serial/flush/
Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.)
To reproduce:
void setup() {
Serial1.begin(115200);
pinMode(2, OUTPUT);
}
void loop() {
digitalWrite(2, HIGH);
Serial1.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Serial1.flush();
digitalWrite(2, LOW);
delay(1);
digitalWrite(2, HIGH);
for (char ch = 'a'; ch <= 'z'; ch++) Serial1.write(ch);
Serial1.flush();
digitalWrite(2, LOW);
delay(1000);
}
Results captured by Logic analyzer:
The hardware appears to have a Transfer Complete (TC) status, which looks like it should be able to do this properly.
Alternatively, is to add some random delay after your transfers to make up for this issue, which I personally would prefer to avoid.
Otherwise, you are likely to see variations of this same issue, like: #389