2020-05-13 02:45 PM
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);
}
2020-05-13 03:22 PM
>>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..
2020-05-13 06:40 PM
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);
}
2020-05-13 10:51 PM
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.
2020-05-14 03:50 AM
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.
2020-05-14 04:20 AM