blackketter
Well-known member
I spent a little too long tracking down an issue with Serial.flush() on a Teensy 3.6 today.
The following sketch doesn't generate any serial output. If I comment out the Serial.flush() it works fine:
The workaround is to not call flush too often, though I'm not sure exactly how often that is.
In my larger project, too frequent calls to Serial.flush() also stopped the Keyboard and Mouse libraries from generating events to the host. Interestingly, in that project connecting a monitor to the virtual serial port somehow slowed things down enough to make the keyboard and mouse work again.
This is with Teensyduino 1.51.
The following sketch doesn't generate any serial output. If I comment out the Serial.flush() it works fine:
Code:
void setup() {
Serial.begin(9600);
delay(1000);
}
int time = 0;
void loop() {
int now = millis()/1000;
if (now != time) {
Serial.println(now);
time = now;
}
Serial.flush();
}
The workaround is to not call flush too often, though I'm not sure exactly how often that is.
In my larger project, too frequent calls to Serial.flush() also stopped the Keyboard and Mouse libraries from generating events to the host. Interestingly, in that project connecting a monitor to the virtual serial port somehow slowed things down enough to make the keyboard and mouse work again.
This is with Teensyduino 1.51.