2016-01-18 08:14 AM
i know how to set properly timer interrupt and it works fine. now i'm trying to create a function to disable interrupt. i should be something like this:
void TimDisableInterrupt(TIM_TypeDef* TIMx){ switch((int)TIMx) { case (int)TIM2: NVIC_DisableIRQ(TIM2_IRQn); break; case (int)TIM3: NVIC_DisableIRQ(TIM3_IRQn); break; case (int)TIM4: NVIC_DisableIRQ(TIM4_IRQn); break; case (int)TIM5: NVIC_DisableIRQ(TIM5_IRQn); break; case (int)TIM6: NVIC_DisableIRQ(TIM6_IRQn); break; case (int)TIM7: NVIC_DisableIRQ(TIM7_IRQn); break; default: break; } NVIC_InitTypeDef nvicStructure; nvicStructure.NVIC_IRQChannelCmd = DISABLE; NVIC_Init(&nvicStructure); TIM_ITConfig(TIMx, TIM_IT_Update, DISABLE); TIM_Cmd(TIMx, DISABLE); TIM_ClearITPendingBit(TIMx, TIM_IT_Update);}so TimDisableInterrupt(TIM6) should disable TIM6 interrupt, but it doesn't work and it continue to go inside here:void TIM6_IRQHandler(void){ if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET) /*do something */ TIM_ClearITPendingBit(TIM6, TIM_IT_Update);}why?i'm using stm32f10x2016-01-19 03:43 AM
Your interrupt handling isn't good. Clearing flag at the end i bad idea. You will get multiply handler execution per 1 event.
__disable_interrupts() _ISB(); -> this can be very important. this bloks next intruction untill interrupt will be disabled. some_instruction