I'm trying to interface a few modules to my STM32L476 board for which I need to enable two GPIO interrupts from the same port (portA, pin 5 and portA, pin 6), but the interrupt handler for these pins are handled by an external line common for pins 5 to 9 (EXTI9_5_IRQHandler).
I need to do a different task on both these interrupts, but how would I know which interrupt has occurred as both are handled by same handler? Are there any flags that I could check to know this?
1 Answer 1
Read the EXTI->PR1
register to decide
void EXTI9_5_IRQHandler(void) {
uint32_t pending = EXTI->PR1;
if(pending & (1 << 5)) {
EXTI->PR1 = 1 << 5; // clear pending flag, otherwise we'd get endless interrupts
// handle pin 5 here
}
if(pending & (1 << 6)) {
EXTI->PR1 = 1 << 6;
// handle pin 6 here
}
}
-
1\$\begingroup\$ What if the pins are from 2 different ports? like 5A and 5B \$\endgroup\$Arun Joe Cheriyan– Arun Joe Cheriyan2017年04月10日 14:43:18 +00:00Commented Apr 10, 2017 at 14:43
-
4\$\begingroup\$ You can't do that. See the description of
SYSCFG->EXTICR
,EXTI5
comes either fromPA5
orPB5
, both is not possible. \$\endgroup\$followed Monica to Codidact– followed Monica to Codidact2017年04月10日 14:50:54 +00:00Commented Apr 10, 2017 at 14:50 -
1\$\begingroup\$ You can store previous (last) states for GPIO_A5 and GPIO_B5, in the ISR check which one was changed. Surely, update the variable with last state upon exiting. Might not work for very short pulse, when pin state is changed back before ISR samples it. If period between pulses are known to be big enough, you can "stretch" very short pulse width with C & R. \$\endgroup\$Flanker– Flanker2017年04月11日 15:16:58 +00:00Commented Apr 11, 2017 at 15:16
-
1\$\begingroup\$ @Flanker, what's C&R? \$\endgroup\$scriptsNgiggles– scriptsNgiggles2019年02月16日 12:46:32 +00:00Commented Feb 16, 2019 at 12:46
Explore related questions
See similar questions with these tags.