cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to handle multiple external interrupts.

STAR
Associate II

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 */

}

10 REPLIES 10
STAR
Associate II

I am using Atollic true Studio

JoniS
Senior

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

Ozone
Lead

Usually one section in "Interrupts and Events".

Here an example from the F40x reference manual:

0690X00000By0S9QAJ.jpg

S.Ma
Principal

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

Pavel A.
Evangelist III

> 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

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.

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

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);

}

}

Piranha
Chief II

The classic HAL way is "fun":

  1. Sort out which line triggered the interrupt from EXTI_PR register.
  2. Pass that information to HAL_GPIO_EXTI_IRQHandler() function.
  3. Get a single HAL_GPIO_EXTI_Callback() function called for all lines.
  4. Sort out which line triggered the callback function once again from GPIO_Pin parameter.

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.

S.Ma
Principal

Yep, IMHO in embedded, ISR focuses on efficiency and short duration, unless you double the core frequency to compensate...

Use the LL for EXTI.