I'd like to know if there is any way to know what is the origin of an external interrupt by programming inside the ISR.
I know I can use a different ISR for each external interrupt and that works but I'm thinking if it's possible to use the same ISR for all external interrupts
If you check the origin pin and trigger condition inside ISR it's not a reliable way to do.
Is there any memory record which store the external interrupt activation?
This is a general question for any AVR microcontroller.
1 Answer 1
Is there any memory record which store the external interrupt activation?
There is, but I do not think it will be easy to exploit.
At low level, each interrupt is handled by a different ISR. So you will
have INT0_vect
handling external interrupt 0 and INT1_vect
handling interrupt 1. These ISRs are all defined by the Arduino
core library. In your case, they will both call the same handler that
you defined. Thus, the information about which ISR fired is now on the
stack: it is the return address of your function.
The reason this information will not be easy to use is that you do not know how far it is from the stack pointer. It depends on how much stuff your own handler pushed onto the stack. You could disassemble it and count, but then your code will be fragile, as the smallest change in the handler (or compiler version) may change this count.
An easier approach may be to define your own INT0_vect
and
INT1_vect
, overriding those from the Arduino core. These new ISRs
will both call your handler, but they will pass it an argument to tell
which interrupt fired.
Or you can register a different handler for each interrupt, each calling a common function. But this adds an extra level of function calls.