External interrupt on atmega AVR

I've been learning to program an AVR (atmega644p) in assembly, but I cannot get it to respond to any interrupts. I am trying to use the external interrupt INT2 on portb,2, but the program does not respond to a signal on the pin either as an input or output.

I have verified all the ports work, and have added LEDs to indicate that the program has reached the wait loop. I have looked at several code examples, and there doesn't appear to be anything missing.

At the moment, I think that the issue may be with the fuses dealing with the boot sector. Fuses are currently set to Low:0xFD, High:0xDF, Extended:0xFF.

Thanks in advance for any suggestions as to what the problem might be.

sort by: active | newest | oldest
Dunno. It looks OK to me too. The interrupt vectors set, you have the global interrupt enable set, you have the mask set and you have the interrupt type set.

What happens if you set the INT2 flag yourself ? and try clearing it in the interrupt routine ?
The Skinnerz (author)  steveastrouk4 years ago
Writing a '1' to the INTF2 bit in the external interrupt flag register to cause the interrupt makes no difference. The program just ends up in the wait loop, ignoring any interrupts that are supposed to happen.

Excluding a problem with the chip itself, the only other thing I can think of is that it previously had a USB bootloader installed (now erased/overwritten), and perhaps the interrupts are being redirected to the bootsector, not the start of the code.
I haven't written on the metal of an AVR so I'm working only from the datasheet, and that says that the setting of the bootloader fuses CAN block interrupt access.
The Skinnerz (author)  steveastrouk4 years ago
I'm fairly sure I've changed the high fuse to disable JTAG (freeing up portc), minimise the size of the bootsector and put the interrupts in the right place. I'll try a few more combinations and see if anything starts working.
Try dispensing with the bootloader, and using SPI programming.
Are you using an Arduino loader, or something else ?
The Skinnerz (author)  steveastrouk4 years ago
I'm using SPI to program the AVR. The programmer erases the memory before writing, so the bootloader shouldn't be there any more. The only information I have on the bootloader is that it is based on the USBaspLoader software to work with the V-USB driver.

I have managed to get intermittent operation with the ADC done interrupt (takes several resets to work, output bits 5 and 6 turn on and off together)
Find an AVR simulator, like this one. http://avr.sourceforge.net/
CLASSIC sign of some kind of initialisation problem then. I've met similar things earlier in my career, before I became infinitely wise and omniscient.....

Short of me hacking on an AVR myself, all I can do is stand on the sidelines and shout words (or bytes) of encouragement ;-)
The Skinnerz (author)  steveastrouk4 years ago
Thanks for all the help.

I'll have another look for some working code examples and try and see where the differences in the initialisation are.
The Skinnerz (author)  steveastrouk4 years ago
Just tried several variations of the fuses with BOOTRST programmed and unprogrammed, but it is still not responding to the interrupt.

I've got the ADC working, which is capable of generating interrupts, so I'll see if the program will respond to that, determining if the problem is with interrupts in general or just with EINT2.
I REALLY recommend playing on a simulator with the code - its always enlightening