What happens if I set the Timer Interrupt Enable flag after the timer overflow flag has been set? Will the interrupt routine fire that time, or only next time an overflow occurs?
Scenario is this:
I have to call a function every 50us, so I made timer interrupt routine call it from time to time.
// Do something non-critical here
TIMSK &= ~ (1<<TOIE0);
// Do something critical here
if (messages pending)
handle 1 message;
remove message from queue;
TIMSK |= (1<<TOIE0);
If I get one message at a time, it works flawlessly. If I send more messages at once, communication stops because the function didn't get called for some reason. The critical part never grows in length, but is called more often during load.
Even if the timer overflow occurs during the critical part, the interrupt routine should be called after reaching the TIMSK |= (1<<TOIE0) instruction, shouldn't it? My guess is that is doesn't get called, and that's why my program doesn't work.