I think that this should be toggling PORTB's first pin, however when I debug it the event is never fired. It seems that the program hangs at sei(). If I manually set TOV2 in TIFR2 then the event fires and the breakpoint set in ISR is reached.
#include <avr/io.h> #include <avr/interrupt.h> int main(void) { DDRD = 0b00000001; cli(); TCCR2A |= (1 << CS20); TIMSK2 |= (1 << TOIE2); sei(); while (1) { } }
The I/O window had the correct bit set.
I thought that it might be that the while loop was getting optimised away by the compiler so I tried adding a write to the PORTB register so that it was doing something important.
while (1) { PORTD++; }
That seems to be preventing the while loop from vanishing but the interrupt at TOV2 still isn't firing.