ATmega16: Interrupt firing without Flag being set

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

The newbie again...

ATmega16, Assembler.

Are there any common reasons for an interrupt (ext. interrupts 0 and 1) to fire without the corresponding interrupt request flag being set? I have absolutely no clue (except direct jumps into the Interrupt Vector table which I don't have) how this can happen.

I have about 600 lines of code (so the error isn't really easy to find) and as soon as the SEI command enables interrupts (the interrupts 1 and 0 are previously enabled), the interrupt vectors are being repeatedly jumped to. None of the two interrupt request flags is set through the whole process though. I ran the thing step by step in the AVR Studio 4.13 simulator and found it out there.

I double checked the PORTD, DDRD and PIND registers (interrupts 1 and 0 are on pins of this port) and tried different settings (output, pullup, whatever) there but no change.

...why? ISRs should only fire when the flag is set!

Markus

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

Simulator is not the most reliable tool, unfortuneally. :(
Maybe try to save GIFR to a register inside ISR and display results on LED's of a port to find out if this really is true.

Quote:
None of the two interrupt request flags is set through the whole process though

Maybe try to write a "1" to those flags before SEI to clear any pending interrupts?

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

I manually wrote a 1 to both flags, no change. I wrote the GIFR to an output port, 0x00. I can't currently test it with real hardware because of another error in the program (EEPROM reading), so I'm tied to the simulator for now.

Markus

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

Well, same answer as in the thread about EEPROM.
Simulator is not a trustworthy friend of yours.
Comment out EEPROM for now and test on >>real chip<< if same phenomena occur.

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

IIRC, with level-triggered external interrupts, the interrupt request flags are bypassed.

Could you post the smallest example code you can come up with that exhibits this behaviour?

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

The problem was the simulator. It does run on the µC but behaves strange in the simulator. Again something learned: never ever rely on a simulator, even not if the company that built the µC gives it to you.

Seems like the AVR Studio assembler simulator has some strange problems...

Thanks guys!

Markus

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

Quote:
Maybe try to save GIFR to a register inside ISR

And this would never really work anyways. By the time you get to the ISR, the flag that caused it would have been reset.

Regards,
Steve A.

The Board helps those that help themselves.

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

Problem solved.

I forgot setting ISC flags in MCUCR, so they defaulted to 0 which is "interrupt on low voltage". The simulator was right and the hardware fast enough for me not to notice the ISRs to be always running ;-)

Markus