In EXTI, how to know which port generates the interrupt?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-01-23 6:35 AM
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
Solved! Go to Solution.
- Labels:
-
STM32MP15 Lines
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-01-23 7:28 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-01-23 6:38 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-01-23 6:54 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-01-23 7:01 AM
Thanks Patrick,
If I want PA0 and PB0 both can generate interrupt, is there a way to do it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-01-23 7:02 AM
These two interrupts won't be triggered at same time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-01-23 7:03 AM
@PatrickF​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-01-23 7:28 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-01-23 7:30 AM
Thank you for the clarification Patrick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-08-02 7:22 AM
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, ...).
I also found some misleading webpages on this topic, so an official document would be definitely help!
Kind regards,
AGA
