Hi
I've read on one of your other threads http://www.gammon.com.au/forum/?id=11488, that I shouldn't "try to do serial reading." in an ISR. I wanted to read some sensor values in a timer interrupt on an Arduino Mega2560, but encountered some serious issues doing so. The code/Arduino simply stops. I've now tried to do a workaround using some flags for the ISR and then implemented my main() as a state machine, but I would really like to know why I can't read in the ISR. I looked into the HardwareSerial class, and to me it looks like the read() function is only returning the data that is already in the rx buffer - I don't see it using any interrupts?
I hope someone can clarify why I can't get this to work the way I want it to :)
Best regards
Jens
I've read on one of your other threads http://www.gammon.com.au/forum/?id=11488, that I shouldn't "try to do serial reading." in an ISR. I wanted to read some sensor values in a timer interrupt on an Arduino Mega2560, but encountered some serious issues doing so. The code/Arduino simply stops. I've now tried to do a workaround using some flags for the ISR and then implemented my main() as a state machine, but I would really like to know why I can't read in the ISR. I looked into the HardwareSerial class, and to me it looks like the read() function is only returning the data that is already in the rx buffer - I don't see it using any interrupts?
I hope someone can clarify why I can't get this to work the way I want it to :)
Best regards
Jens