Detect which interrupt called an ISR on ATmega

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

I want to have a single ISR handling the eight INTn external interrupts on a ATmega2560, using ISRALIASOF(INT0_vect) for INT1 to INT7.

 

Is there a way within the ISR to detect which input caused the interrupt? I've tried reading EIFR, but it's already cleared by the time I'm in the ISR.

 

Of course I could define eight ISRs all calling the same routine with a parameter 0 to 7, but that seems a bit messy.

 

Thanks, David

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

Why can't you read the PIN registers of the ext-int pins and just note which changed since last time? (which is what you do for PCINT to determine which of 8 caused it) 

 

But why ALIASOF in the first place? 

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

Thanks for the quick reply!

Why can't you read the PIN registers of the ext-int pins and just note which changed since last time? (which is what you do for PCINT to determine which of 8 caused it) 

Because if it was a brief pulse and I'm detecting the rising edge it might be low again by the time I'm in the ISR.

But why ALIASOF in the first place?

How else would I do it without having eight ISRs? 

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

I think you've answered your own question - if there is no mechanism to determine who interrupted, then you need 8 isrs that identify what input interrupted.

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

What exactly is wrong with 8 ISR() s? 

 

If this is about maintaining 8 copies of almost identical code then put the common bits into an "__attribute__((always_inline)) static inline" function and invoke that from each. 

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

OK, thanks. I'll try that out.

 

David

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

johnsondavies wrote:
How else would I do it without having eight ISRs?
clawson wrote:
What exactly is wrong with 8 ISR() s?

+1.

 

As Cliff mentioned, the common core code can be isolated, and invoked with "inline" routine or [gasp] goto.

 

There are other esoteric ways.  For example, if you keep the ISR code close enough to the vector table to be reached with RJMP then you can LDI a flag value in the other vector word.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.