Electronic – Not entering ISR for timer 4 in stm32f4

interruptsstm32f4timer

I have coded for Timer 4 in a STM32f407vg discovery board. But while debugging the control is not entering the ISR. Please find the code below and help:

void InitializeTimer()
{

    TIM_TimeBaseInitTypeDef timerInitStructure;

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);

    timerInitStructure.TIM_Prescaler = 0;

    timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;

    timerInitStructure.TIM_Period = 255;

    timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
    timerInitStructure.TIM_RepetitionCounter = 0;

    /*Initialise timer 4 */
    TIM_TimeBaseInit(TIM4, &timerInitStructure);
    TIM_Cmd(TIM4, ENABLE); 



}


void EnableTimerInterrupt()
{

    NVIC_InitTypeDef nvicStructure;
    nvicStructure.NVIC_IRQChannel = TIM4_IRQn;
    nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;
    nvicStructure.NVIC_IRQChannelSubPriority = 1;
    nvicStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&nvicStructure);
}

void TIM4_IRQHandler(void)
{


if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
    {


        TIM_ClearITPendingBit(TIM4, TIM_IT_Update);

    }

}

With this configuration I am not able to enter an ISR.

Best Answer

You not only have to configure the timer mode, interval etc. and enable it but you also have to tell the timer on what events should the interrupt be generated. You can do this with a function:

void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState);

This is obviously because the timer may generate an interrupt signal for many different reasons, not just when it for example overflows.