cancel
Showing results for 
Search instead for 
Did you mean: 

MAY i use Interrupt handler multiple times ?

ALE1
Associate II

In the follwoing code i would like to use same interrupt multiple times in order to blink the 4 leds different time.

i am storing the data in unint8_t ABB, i expect that each time i press the button the value in ABB is incremented but practically not working, where am i wrong ?

void EXTI1_IRQHandler(void)

{

if(EXTI_GetITStatus(EXTI_Line1))

ABB=(GPIO_ReadInputData(GPIOA) & GPIO_Pin_1);

if(ABB==0x00) //Button is pressed first time

LED1(); //GreeN

if(ABB==0x01) //Button is pressed 2nd time

LED2(); //White

if(ABB==0x10) //Button is pressed 3rd time

LED3(); //Yellow

if(ABB==0x11) //Button is pressed 4th time

LED4(); //RED

EXTI_ClearITPendingBit(EXTI_Line1);

}

5 REPLIES 5

>>i am storing the data in uint8_t ABB, i expect that each time i press the button the value in ABB is incremented but practically not working, where am i wrong ?

You don't increment anything, or differentiate first or secondary entry..

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

Clive1 is correct. you aren't incrementing anything. Use ABB as a global flag:

void EXTI1_IRQHandler(void)

{

static int count = 0;

if ((GPIO_ReadInputData(GPIOA) & GPIO_Pin_1)) //Use to verify it is the button pin. Change to whatever make sense for you.

{

 count++;

if(count==0x00) //Button is pressed first time

LED1(); //GreeN

if(count==0x01) //Button is pressed 2nd time

LED2(); //White

if(count==0x10) //Button is pressed 3rd time

LED3(); //Yellow

if(count==0x11) //Button is pressed 4th time

LED4(); //RED

}

EXTI_ClearITPendingBit(EXTI_Line1);

}

S.Ma
Principal

If the real purpose is to blink LED and if the blinking doesn't need to be done within microseconds after the EXTI, just raise a flag on the interrupt side, poll it on the main loop, and act/clear this flag from the non time critical interrupt service routine (ISR). Usually I try to keep the interrupt as light and snappy as possible.

When the interrupt events grows, it starts to make a difference.

Thanks for your reply But!

in your case, only single press is needed and all LEDS blink at the same time.

because count++ is incrementing without reading second press.

actually i want to use the same interrupt 4 times for 4 different LEDS.

  • What does the function LED1(); do? if you want to toggle the LED you have to add an else to each if and turn it off
  • you know that count==0x10 is Hexadecimal? that mens the button is pressed here for the 16th time, not 3rd as commented.