AnsweredAssumed Answered

TIM1 ISR not triggering - STM32f4xx

Question asked by naphtali on Sep 17, 2013
Latest reply on Jan 17, 2014 by naphtali
I am trying to use the ISR for TIM1, but it does not want to trigger. I run the following code in debug mode on my IDE, but the TIM1 ISR code never gets executed.

I believe that the problem may have something to do with an extra enable needed for the advanced control timers, but have yet been unable to find it.

Also, I would appreciate any tips on how to make the following code more readable for you.

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private Variables */
uint16_t uhPrescalerValue = 0;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Functions */


int main(void)
{
     uhPrescalerValue = (uint16_t) ((SystemCoreClock / 2) / 10000000) - 1;
     
      /* TIM clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
     
      /* Enable the TIM4 interrupt */
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  
     NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
     NVIC_Init(&NVIC_InitStructure);
     
     NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
  NVIC_Init(&NVIC_InitStructure);


     /* Time Base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = uhPrescalerValue;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;


  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
     TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
     
     //Enable TIM1 output
     TIM_CtrlPWMOutputs(TIM1,ENABLE);
     
     /* TIM counter enable */
  TIM_Cmd(TIM1, ENABLE);
     TIM_Cmd(TIM4, ENABLE);
     
     //TIM IT Config
     TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);
     TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
     
     while (1){
     }
}
void TIM4_IRQHandler(void) {
     TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
}
void TIM1_CC_IRQHandler(void) {
     TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
}
void TIM1_CC_IRQHandler(void);
void TIM4_IRQHandler(void);

Outcomes