2020-02-03 03:26 AM
How to handle multiple External (more than 2 )interrupts on same port (eg Port A) of STM32. my code is below , I wants to know that how can I Differentiate External interrupt 0 And 1. I have configured pushbutton1 on PA0, Pushbutton2 on PA1, pushbutton3 for PA2 and pushbutton4 For PA3 of Rising Edge. I have Given Same Priority to all interrupts. Thanks In Advanced.
void EXTI0_1_IRQHandler(void)
{
/* USER CODE BEGIN EXTI0_1_IRQn 0 */
/* USER CODE END EXTI0_1_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
/* USER CODE BEGIN EXTI0_1_IRQn 1 */
/* USER CODE END EXTI0_1_IRQn 1 */
}
void EXTI2_3_IRQHandler(void)
{
/* USER CODE BEGIN EXTI2_3_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
/* USER CODE END EXTI2_3_IRQn 0 */
/* USER CODE BEGIN EXTI2_3_IRQn 1 */
/* USER CODE END EXTI2_3_IRQn 1 */
}
2020-02-03 03:29 AM
I am using Atollic true Studio
2020-02-03 06:19 AM
Typical when interrupt fires it does set X bit in the periephal register as a indication of the interrupt.
You would need to check the datasheet of your microcontroller to see which bit is set for each of those interrupts, then read the interesting bits to see which was the cause of the interrupt when the ISR fires.
2020-02-03 07:08 AM
Usually one section in "Interrupts and Events".
Here an example from the F40x reference manual:
2020-02-03 08:14 AM
It doesn't matter, the interrupts being same priority will be queued and their duration should be pretty short.
If it's a human push button, unless it's to wake up from low power mode, EXTI maynot be needed. If you poll the GPIO every 50msec, you will be able to simply confirm key pressed if say 3 times in a row the pin is low. Push buttons are glitchy and debounce.
Otherwise, just add which action you want inside the ISR or in the unique callback function (then you need to again to find out which pin cause the interrupt).
2020-02-03 04:45 PM
> I wants to know that how can I Differentiate External interrupt 0 And 1.
> void EXTI0_1_IRQHandler(void)
It depends on the STM32 model. Some of them support separate vectors for EXTI0 and EXTI1, so the issue simply disappears.
There will be two different handlers instead of one EXTI0_1_IRQHandler.
Make sure this code example applies to your specific model.
-- pa
2020-02-03 05:04 PM
You should still be able to differentiate the source(s) via flagging in the EXTI peripheral itself. They are combined into grouped EXTI IRQs down stream.
2020-02-03 09:57 PM
I Differentiate using below code. Thank you. I Faced one problem is that when I pressed pushbutton1 then pushbutton2 but in Handler no any thing like(void EXTI0_1_IRQHandler(void){;}) then I pressed Bushbutton3 and pushbutton4 But Handler having some instructions but it not executes . I pressed 1st pushbutton3 and then bushbutton4 its working.
void EXTI0_1_IRQHandler(void)
{
if ((EXTI->PR & EXTI_PR_PR1))
{
EXTI->PR |= EXTI_PR_PR1;
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_1);
}
if ((EXTI->PR & EXTI_PR_PR0))
{
EXTI->PR |= EXTI_PR_PR0;
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
}
}
void EXTI2_3_IRQHandler(void)
{
if ((EXTI->PR & EXTI_PR_PR2)) /* Check line 1 has triggered the IT */
{
EXTI->PR |= EXTI_PR_PR2; /* Clear the pending bit */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_2);
}
if ((EXTI->PR & EXTI_PR_PR3)) /* Check line 0 has triggered the IT */
{
EXTI->PR |= EXTI_PR_PR3; /* Clear the pending bit */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
}
}
2020-02-08 04:46 AM
The classic HAL way is "fun":
Really "helping" library!
Now they have introduced a separate driver for EXTI (stm32XXxx_hal_exti.c). Of, course it's still made by code monkeys, but at least one can attach a dedicated callback function to each EXTI line with it.
2020-02-08 05:09 AM
Yep, IMHO in embedded, ISR focuses on efficiency and short duration, unless you double the core frequency to compensate...
Use the LL for EXTI.