Question
Why is my timer 4 interrupt issued as soon as I enable the interrupt?
Posted on February 01, 2016 at 10:26
I want to generate an interrupt after 2 seconds and I am running at 32 MHz. However, my interrupt is issued as soon as I enable the interrupt. What am I doing wrong?
void testTimer4(EventCallback_t timerInterruptCallback)
{
timerInterruptCallback_ = timerInterruptCallback;
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
TIM4->PSC = 976;
TIM4->ARR = 65505;
TIM4->CNT = 0;
TIM4->SR &= (~TIM_SR_UIF);
TIM4->DIER |= TIM_DIER_UIE;
HAL_NVIC_EnableIRQ(TIM4_IRQn);
TIM4->CR1 |= TIM_CR1_CEN;
}
void TIM4_IRQHandler(void)
{
TIM4->SR &= (~TIM_SR_UIF);
HAL_NVIC_DisableIRQ(TIM4_IRQn);
TIM4->DIER &= (~TIM_DIER_UIE);
TIM4->CR1 &= (~TIM_CR1_CEN);
RCC->APB1ENR &= (~RCC_APB1ENR_TIM4EN);
(void)timerInterruptCallback_((uint32_t)TIMER_4_EXPIRED, 0);
}