MCU: Atmega328P IDE: Microchip Studio v7.0.2594 Toolchain: Atmel AVR 8-bit (C language) Native I am trying to run Timer0 Overflow interrupt. However, it seems like ISR is not getting executed. The Pin toggles inside while(1) but stays LOW when operated inside ISR Same kind of issues happen when I try to run Atmega2560 Timers. Here is my basic code. I have worked on many Atmega MCUs but this has never happened before. Note: Observing the signal pin using a Logic Analyzer.
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
ISR(TIMER0_OVF_vect)
{
PORTB ^= (1<<5); //Toggle once in every 8.12ms
TCNT0 = 127;
}
int main(void)
{
/* Replace with your application code */
DDRB = (1<<5);
PORTB = 0;
TCCR0A = 0;
TCNT0 = 127;
TIMSK0 = (1<<TOIE0);
TIFR0 = 0;
TCCR0B = (1<<CS02)|(1<<CS00); // CLKio Divide by 1024
//Duration of 1 count = 16MHz/1024 = 15.625KHz = 64us
//Duration of 127counts = 64*127 = 8.12ms
sei();
while (1);
{
PORTB ^= (1<<5);
_delay_ms(10);
}
}
When I disable the interrupt using //sei(); or //TIMSK0 = (1<<TOIE0); The code inside while 1 works fine
while (1) ;, noticed the;at the end?