Can ISR Find Out the Interrupt Number?

Pretty sure I know the answer to this, but ..... is there a function defined somewhere in the Arduino “core” that can be called from an ISR to determine which interrupt number fired?

I’m specifically interested in External Pin interrupts. I want the interrupt number, not the pin number. I imagine that the telltale flag bits are cleared before the attached ISR gets called. Even if they weren’t the ISR would have to access different flag registers for each type of processor (AVR, Teensy Kinetis, Feather SAMD, etc). So, that’s why I’m wondering if there’s a standard function call that will provide the info.

Thanks.

If an interrupt service routine is called, that would correspond directly to an interrupt number (at least on AVR based processors).

Please explain what you really want to do.

jremington:
If an interrupt service routine is called, that would correspond directly to an interrupt number.

Please explain what you really want to do.

That's exactly what I want to do. The same ISR will be called for multiple interrupts.

No, only one interrupt per routine. If you believe otherwise, please provide an example.

In the case of pin change interrupts, you do need to find out which pin triggered the interrupt, by reading the port and comparing to a saved value.

The same ISR will be called for multiple interrupts.

But they all came via their own vectors (hint)

jremington:
No, only one interrupt per routine.

In the case of pin change interrupts, you do need to find out which pin triggered the interrupt, by reading the port and comparing to a saved value.

Looking at the source code for attachedInterrupt(), I see no reason the same ISR can't be attached to multiple interrupts -- for a Teensy 3.x anyway. The same function pointer would simply exist in multiple entries in the table.

I'm not interested in pin change interrupts. Just the ones that are usable with attachedInterrupt().

Anyway, what I want to know is as stated in my original question. That remains unanswered.

I’m not interested in pin change interrupts. Just the ones that are usable with attachedInterrupt().

You’re probably confused with “attachInterrupt”

I would go with your opening statement...

Pretty sure I know the answer to this

jremington:
No, only one interrupt per routine. If you believe otherwise, please provide an example.

https://www.google.com/search?q=ISR_ALIASOF

(Posted with trepidation.)

Thanks, I now realize that with "clever" programming, it is indeed possible to make life more difficult that necessary!

I think you could use something like this. Tested on Teensy 3.2.

Code:





```
#define attachMyInterrupt(pin, mode) attachInterrupt(digitalPinToInterruptcolor=#000000[/color], +[]color=#000000[/color]{ myInterruptHandlercolor=#000000[/color]; }, mode)

void myInterruptHandler(uint8_t pin) {
  // use pin here
  if (pin == 4)
    digitalWrite(LED_BUILTIN, HIGH);
  else if (pin == 5)
    digitalWrite(LED_BUILTIN, LOW);
}

void setupcolor=#000000[/color] {
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(LED_BUILTIN, OUTPUT);
  attachMyInterrupt(4, FALLING);
  attachMyInterrupt(5, FALLING);
}

void loopcolor=#000000[/color] {}
```

|

Note that ‘pin’ must be a compile-time or global constant.

Pieter

PieterP:
I think you could use something like this. Tested on Teensy 3.2.

I thought of the lambda function trick. But, your take is slightly different than what I was thinking. It just might work for me.
Thanks!!!