sylvaing19
Member
I am currently trying to communicate through UART inside a timer interrupt, and I'm facing a strange issue when calling the flush() function. Here is a simple code to reproduce the problem :
I am using a Teensy 3.2 and the Arduino IDE.
The output on the usb serial if the following :
Begin setup
End setup
So apparently the teensy is frozen...
If you comment the line "Serial1.write(0x42);" OR the line "Serial1.flush();" aka if you don't flush or if there is nothing to flush then the code will run fine an you get the following output :
Begin setup
End setup
Begin interrupt
End interrupt
Begin interrupt
End interrupt
Begin interrupt
End interrupt
etc...
It is probably an interrupt-related issue, but I can't find exactly what is wrong.
I hope you can help me with that
Thanks,
Sylvain
Code:
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
void loop() {
delay(500);
Serial.println("Begin setup");
Serial1.begin(115200);
IntervalTimer timer;
timer.priority(64);
timer.begin(interruptFunction, 500000);
Serial.println("End setup");
while(true);
}
void interruptFunction()
{
Serial.println("Begin interrupt");
Serial1.write(0x42);
Serial1.flush();
Serial.println("End interrupt");
}
I am using a Teensy 3.2 and the Arduino IDE.
The output on the usb serial if the following :
Begin setup
End setup
So apparently the teensy is frozen...
If you comment the line "Serial1.write(0x42);" OR the line "Serial1.flush();" aka if you don't flush or if there is nothing to flush then the code will run fine an you get the following output :
Begin setup
End setup
Begin interrupt
End interrupt
Begin interrupt
End interrupt
Begin interrupt
End interrupt
etc...
It is probably an interrupt-related issue, but I can't find exactly what is wrong.
I hope you can help me with that
Thanks,
Sylvain