Interrupt Returning to wrong point in code...

I should also point out that if you are debugging at 9600 baud (as the OP is) then even if the ISR doesn't hang, it will wait while the bytes are shifted out.

Example message:

Enter isr_timer(no exit)

Each byte takes 1/960 seconds (1.04 ms) and there are 26 bytes there if you include the CR/LF. So that is a 27 ms delay to send the debugging message. Straight away that puts out the millis() timer by around 26 counts, because 26 timer overflows have been missed.

So if the thing you are "debugging" is (amongst other things maybe) timing figures, then they will be way out.

  • This assumes that the serial buffer is full, which it may well be if you are outputting wordy debugging messages at 9600 baud.