2017-09-13 01:07 AM
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
andEXTI_ClearITPendingBit, but I don't have these functions defined in any header.
Should CubeMx provide these in a header and how do I make CubeMX do this?
Where do I find documentation for EXTI_GetITStatus and
EXTI_ClearITPendingBit or whatever functions I should use instead?
Solved! Go to Solution.
2017-09-13 02:52 AM
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
2017-09-13 02:52 AM
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
2017-09-13 03:12 AM
Those would be functions in the SPL, look for equivalent functions in the HAL exti.c source file?
2017-09-13 03:31 AM
>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.
2017-09-14 10:48 AM
,
,
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.
2019-01-30 06:41 AM
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
2019-01-30 08:34 AM
You can only have a pin source in a single GPIO bank.
Ie PC12 PB11 PA10 PC9 etc
PC12 and PA12 is not a workable combination.
2019-01-30 10:20 PM
Ah ok makes sense.
Thanks for the quick reply :)