user27056768
user27056768

Reputation: 1

AVR ATmega328p Timer Interrupt not working

I'm trying to make a blinking led in assembly on my ATmega328p. I am using the 8 bit timer to try and make this happen. Right now the timer is set to move super fast so that I can test it in Atmel Studio. I watched the bytes as the program went on and noticed that the interrupt flag was set, but my interrupt function did not execute. Help?

LDI r16, (1 << DDB0)
OUT DDRB, r16

LDI r16, (1 << WGM01) ;set CTC mode
OUT TCCR0A, r16 ;set data to the TCCR0A register

LDI r16, 0x10
OUT OCR0A, r16 ;set tick amount

SEI ;global interrupt enable, CLI to disable

LDI r16, (1 << OCIE0A)
STS TIMSK0, r16

LDI r16, (1 << CS00); | (1 << CS02) ;select prescaler
OUT TCCR0B, r16; set data to TCCR0B register and start timer

rjmp MAIN

.org  0x001C
    rjmp TIMER_INTERRUPT

MAIN:
    rjmp MAIN

TIMER_INTERRUPT:
    IN r16, PORTB
    LDI r17, (1 << PORTB0)
    EOR r16, r17
    OUT PORTB, r16
reti

I tried checking all bits after each instruction to make sure I was setting things up correctly, and that seems to have brought up no visible errors.

Upvotes: 0

Views: 60

Answers (1)

Peter Plesn&#237;k
Peter Plesn&#237;k

Reputation: 819

You probably tested the code using stepping in the simulator, then you have a disabled execution of the ISR in stepping mode.

It is necessary to change the setting flag Mask interrupts while stepping. You should set the flag to false. You can find this flag in the Tools menu, Options... item, then Tools

Enable ISR in single step

Upvotes: 0

Related Questions