cancel
Showing results for 
Search instead for 
Did you mean: 

EXTI15_10_IRQn, how to seperate interrupts

Krix N
Associate II
Posted on September 13, 2017 at 10:07

Beginner working with STM32L452:

I have enabled interrupts for some GPIO pins through CubeMx.

CubeMX generates this function, and it gets called as expected on GPIO interrupt:

void EXTI15_10_IRQHandler(void)

How do I distinguish between which pin or line was triggering the interrupt?

I have found some examples using

EXTI_GetITStatus

and

EXTI_ClearITPendingBit, but I don't have these functions defined in any header.

  1. Should CubeMx provide these in a header and how do I make CubeMX do this?

  2. Where do I find documentation for EXTI_GetITStatus and

    EXTI_ClearITPendingBit or whatever functions I should use instead?

#interrupts #exti_getitstatus #gpio #exti15_10_irqn
1 ACCEPTED SOLUTION

Accepted Solutions
Tilen MAJERLE
ST Employee
Posted on September 13, 2017 at 11:52

Hello

‌,

Cube generated for you this IRQ function and content of it should be similar to:

HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);�?�?

What you have to do is to implement callback in your user code (for example in main.c), which will be called from HAL driver.

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ if (GPIO_Pin == GPIO_PIN_13) { /* DO the job when EXTI was detected on pin 13 */ }}�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Exact example is available in your L4 cube package:Projects\STM32L476G_EVAL\Examples\GPIO\GPIO_EXTI\Src

Best regards,

Tilen

View solution in original post

7 REPLIES 7
Tilen MAJERLE
ST Employee
Posted on September 13, 2017 at 11:52

Hello

‌,

Cube generated for you this IRQ function and content of it should be similar to:

HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_13);�?�?

What you have to do is to implement callback in your user code (for example in main.c), which will be called from HAL driver.

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){ if (GPIO_Pin == GPIO_PIN_13) { /* DO the job when EXTI was detected on pin 13 */ }}�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Exact example is available in your L4 cube package:Projects\STM32L476G_EVAL\Examples\GPIO\GPIO_EXTI\Src

Best regards,

Tilen

Posted on September 13, 2017 at 12:12

Those would be functions in the SPL, look for equivalent functions in the HAL exti.c source file?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
john doe
Lead
Posted on September 13, 2017 at 12:31

>How do I distinguish between while pin or line was triggering the interrupt.

let the HAL do the work for you.

in the stm32l4xx_hal_gpio.h header file, they define a callback:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);

you get which pin it is passed to you in the callback routine. the HAL automagically clears the flag for you. both the callback and the irq handler are defined weakly so you can write your own if you want.

Posted on September 14, 2017 at 17:48

 ,

 ,

The auto generated main.h file has some nice ♯ define statements to make your code more readable. Use the appropriate _Pin definition in place of GPIO_PIN_xx. Also, you will see that there is an interrupt _IRQn definition which is useful for enabling and disabling specific interrupts.

Flo
Associate II

Hello,

I know that this thread is a bit outdated but I have a similiar problem where this already existing question matches pretty well.

My question is, how can I distinguish which Port caused the interrupt in the HAL_GPIO_EXTI_Callback(GPIO_Pin); ?

This function is specially defined as weak so I can implement my interrupt application in here instead of using the EXTI15_10_IRQHandler(void) which also has options for user code but can't be moved without getting a new one after code generation.

But how do I know if the interrupt was caused by Pin PC12 and not PB12 or PA12?

In both interrupt functions I only have the pin number as a paramter.

Is there an elegant way to check from which port the interrupt originated inside the callback?

Thank you in advance,

Best Regards

Flo

You can only have a pin source in a single GPIO bank.

Ie PC12 PB11 PA10​ PC9 etc

P​C12 and PA12 is not a workable combination.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Ah ok makes sense.

Thanks for the quick reply :)