Skip to main content
Visitor II
January 23, 2023
Solved

In EXTI, how to know which port generates the interrupt?

  • January 23, 2023
  • 3 replies
  • 5287 views

Hi,

After reading the document I understand the interrupts are handled by pin#, and we set GPIOsel within EXTI_ConfigTypeDef.

My question is how do we determine which port generates the interrupt?

Suppose I use PA0 and PB0, and I only want to use one callback function for them.

void callback()

{

if(port == GPIOA)

{

do something

}

else if(port == GPIOB)

{

do other thing

}

}

Thank you

    This topic has been closed for replies.
    Best answer by PatrickF

    Hi, unfortunately, EXTI cannot be programmed for PA0 and PB0 (you should have seen this restriction when you started your design with CubeMX).

    Some possible solutions (just for your information, not tested):

    • move one pin to another GPIO (e.g. move PB0 to PB1)
    • If you know when you are expecting the interrupt for each pin (which is rarely the case), then you could reprogram EXTI whenever needed.
    • You could merge externally the two lanes to same pin (gate or diodes if slow enough) for interrupt purposes while you still connect the two to distinct port to check pin level in interrupt routine (risk of 'ghost' interrupt if disappear before been handled)
    • You could use IO expander with interrupt feature (usually control by I2C)
    • In the particular case of PA0, you might be lucky as you could probably use WKP1 feature (thru PWR, not EXTI) as workaround (and keep PB0 to EXTI).

    Regards.

    3 replies

    dchenAuthor
    Visitor II
    January 23, 2023

    I know one way is to set EXTI_ConfigTypeDef exti_config as a global variable, and pass it into the callback function. Is there another way to do it?

    Technical Moderator
    January 23, 2023

    Hi,

    your example wont fly as you cannot have at same time EXTI0 set for PA0 and PB0.

    If you MUXSEL is not static (i.e. dynamic SW changes from PA0 to PB0 and vice-versa), in the interrupt routine, you could check the content of EXTI_EXTICR1.EXTI0 (example for EXTI0) to know if interrupt was set to PA0, PB0, PC0, etc. This could save you some global variable.

    Regards.

    dchenAuthor
    Visitor II
    January 23, 2023

    Thanks Patrick,

    If I want PA0 and PB0 both can generate interrupt, is there a way to do it?

    dchenAuthor
    Visitor II
    January 23, 2023

    These two interrupts won't be triggered at same time.

    dchenAuthor
    Visitor II
    January 23, 2023

    @PatrickF​