cancel
Showing results for 
Search instead for 
Did you mean: 

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

dchen
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions

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.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

8 REPLIES 8
dchen
Associate II

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?

PatrickF
ST Employee

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.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
dchen
Associate II

Thanks Patrick,

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

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

@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.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Thank you for the clarification Patrick

Hi @PatrickF,

your answer has been super useful to me too! Many thanks!!!

In the datasheet is not reported that "only one line" can work at the time. From the picture looks like that the EXTIx is shared across all these inputs (PA0, PB0, PC0, ...).

superaga_0-1690985801524.png

I also found some misleading webpages on this topic, so an official document would be definitely help!

Kind regards,

AGA