For a quite while, I've been using an avr ATmega324PA controller and Atmel studio to write the programs. we wrote a TCP bootloader. It works fine without any interrupt. Later we did add an external inetrrupt to that program and now controller always restarts when jumping to the ISR. Here is the code
void main()
{
init_interrupt();
init_uart();
while(1);
}
void init_interrupt()
{
/* PortA3 as input for external interrupt*/
DDRB|=(0<<2);
/*Pulll up disable*/
PORTB &=~ (1<<PORTB2);
/*Interrupt_vector change enable*/
MCUCR|=(1<<IVCE);
/*Interrupt vector change to boot section*/
MCUCR|=(1<<IVSEL);
/*Interrupt_vector change enable*/
MCUCR&=~(1<<IVSEL);
_delay_ms(5000);
/* Enable external interrupt-2*/
EIMSK |= (1<<INT2);
/* Enable rising edge of the input signal as interrupt*/
EICRA |= (1<<ISC21)|(1<<ISC20);
/* Enable global interrupt*/
sei();
}
ISR(INT2_vect)
{
uart_send("Print on interrupt");
}
Here i am trying to change the interrupt vector to boot section.
NOTE: BOOTRST fuse is already set
EDITED: After changing the MCUCR value as shown below, i sent it through UART instead of '01', the output is displayed as "A0 2E 57 C9 D1 95 91 FF"
MCUCR|=(1<<IVCE);
Must be a problem with the MCUCR register