cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt issue with timers and exti0

hexfet13
Associate II
Posted on June 01, 2015 at 17:09

Hi all, i'm new to cortex M4 STM32F4 processor and i have some problems with external interrupt handling and internal timer interrupt. Currently i'm trying this code on a DISCOVERY F4 board (with STM32F407) and i'm trying to use a delay function addociater to a button pressure (only to perform a anti-bounce function, without external capacitor connected ti user button) with this code:

void EXTI0_IRQHandler(){

    NVIC_DisableIRQ(EXTI0_IRQn);

    EXTI_ClearITPendingBit(EXTI_Line0);

    btnPressed=1;

    delay_ms(100);

    NVIC_EnableIRQ(EXTI0_IRQn);

}

//interrupt every 1ms

void TIM7_IRQHandler(){

     TIM_ClearITPendingBit(TIM7, TIM_IT_Update);

     sysTimer++;

     if (!(sysTimer%100)) GPIO_ToggleBits(GPIO_LED,LD_GREEN);//alive led

}

Well, the code stops at ''delay_ms(100)'' function when i press the user button. This is bacause the sysTimer freeze it's content, because TIM7_IRQHandler isr is not server anymore. Inspecting the NVIC register i see the ISER0=10000040 before  NVIC_DisableIRQ(EXTI0_IRQn) instruction and  ISER0=10000000 . So timer2 and timer7 interrupts should works but this is not.

Can anyone tell me why? where is the mistake?
2 REPLIES 2
Posted on June 01, 2015 at 17:23

It's considered poor practice to use delays in interrupt code, especially ones dependent on other interrupts to function. Going to need to watch the pre-emption levels. Would recommend you read a free running hardware timer either a TIMx or DWT->CYCCNT and delta against the value in that instead of a variable.

Disabling this interrupt doesn't impact if others can fire, you have to return from this one.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hexfet13
Associate II
Posted on June 01, 2015 at 19:15

Thanks for your reply.

I was tring to disable the EXTI0 interrupt to prevent reentrancy to the same ISR caused by push button switch bounce; but the problem is that all other interrupt stops working: TIM7 does not increment sysTimer anymore and neither TIM2 works at all.

I tried to modify the priority and sub priority af all interrupt sources without effect and then i tried to configure PriorityGroup adding this

 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

before all definition of interrupts. And now, the program works as expected: i have the correct delay within EXTI0 interrupt.

Thanks again!