Control not passing to ISR.

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

#define F_CPU 1000000UL     
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>

// global variable to count the number of overflows
volatile uint8_t tot_overflow;
void timer0_init(void);
// initialize timer, interrupt and variable
void timer0_init()
{
    // set up timer with prescaler = 256
    TCC0.CTRLA = TC_CLKSEL_DIV256_gc;
    
    
    
    // initialize counter
    
    TCC0_CNT = 0;
    
    
    // enable overflow interrupt
    TCC0.INTCTRLA = TC_OVFINTLVL_LO_gc;
    // enable global interrupts
    sei();
    
    // initialize overflow counter variable
    tot_overflow = 0;
}

ISR(TCC0_OVF_vect)
{
    // keep a track of number of overflows
    tot_overflow++;
}

int main(void)
{
    // led 
    PORTR_DIRSET = 0x03;
    
    // initialize timer
    timer0_init();
    
    // loop forever
    while(1)
    {
        
        if (tot_overflow >= 12)  
        {
           
            if (TCC0_CNT >= 53)
            {
                PORTR_OUTSET= 0x02;
                _delay_ms(100);
                PORTR_OUTCLR = 0x02;    // toggles the led
                
                TCC0_CNT = 0;            // reset counter
                tot_overflow = 0;     // reset overflow counter
            }
        }
    }
}

Above is my code to toggle a LED in ATXMEGA256A3BU, but the control is not passing on to the ISR and getting stuck at tot_overflow if loop.

Nitin Shenoy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is an interrupt controller in xmega, please set it.
Otherwise, all interrupts are not enabled.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Doesn't SEI do that?..Enabling interrupts

 

Nitin Shenoy

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Read the data sheet carefully.