Question
I cannot get my EXTI to function properly with a flashing LED
Posted on October 23, 2016 at 16:12
Hi there. I am using the STM32VLDISCOVERY board with Atollic Studio.
I'm pretty new to programming, so getting any code to run can be a bit of a challenge for me! I am trying to implement a program which will cause an LED to flash when I press a button, and then stop flashing when I press the button again. I can get the LED to flash when I press the button, but I cannot stop it flashing when I press the button again. Previously, I was able to get this program to work when I only wanted to turn the LED on and off, so I figure that the loop I'm using won't detect the change in status of the push button.I know there isn't any issue with the initialization of the push button and LED, so I'll just post the code I'm using in the EXTI block. The following is located in stm32f1xx_it.c void EXTI0_IRQHandler(void){ if(EXTI_GetITStatus(EXTI_Line0) != RESET) { if (GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_9)==0) { for(;;) { /* Turn ON LED */ GPIO_SetBits(GPIOC, GPIO_Pin_9); /* Delay */ for(int i = 0; i<=200000 ; i++); /* Turn OFF LED */ GPIO_ResetBits(GPIOC, GPIO_Pin_9); /* Delay */ for(int i = 0; i<=200000 ; i++); /* Clear the User Button EXTI line pending bit */ EXTI_ClearITPendingBit(EXTI_Line0); } } } else { /* Turn OFF LED */ GPIO_ResetBits(GPIOC, GPIO_Pin_9); /* Clear the User Button EXTI line pending bit */ EXTI_ClearITPendingBit(EXTI_Line0); }}I've tried implementing using a few other methods, but nothing seems to be working for me. Any small help would be greatly appreciated. Thanks! #exti #button #stm32 #interrupt