I was building a simple blink application on an STM8S. The LED on-off interval was controlled by the delay function using the TIM4 interrupt. A button event monitor is using another external interrupt to prevent interference from the timer interrupt.
I found that the button event is not interrupted by the delay function, but the function associated with it still gets interrupted by the delay function. It will only execute after delay() returns no matter how early I press the button.
Is there a way to bypass this? Should I enable another timer (like TIM2) to independently handle the button event? I need some insights.
The button is controlled by the code here:
INTERRUPT_HANDLER(EXTI_PORTE_IRQHandler, 7) { /* In order to detect unexpected events during development, it is recommended to set a breakpoint on the following instruction. */ //if the Button is pressed if(mode == 2) { mode = 0; } else { mode ++; } } main.c
void main(void) { CLK_Config(); GPIO_Config(); TIM4_Config(); /* Infinite loop */ while (1) { Switch_Blink_Pattern(mode); } } The delay function is from STM's demo, using TIM4:
INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler, 23) { /* In order to detect unexpected events during development, it is recommended to set a breakpoint on the following instruction. */ TimingDelay_Decrement(); /* Cleat Interrupt Pending bit */ TIM4_ClearITPendingBit(TIM4_IT_UPDATE); } void Delay(__IO uint32_t nTime) { TimingDelay = nTime; while (TimingDelay != 0); } void TimingDelay_Decrement(void) { if (TimingDelay != 0x00) { TimingDelay--; } }