AnsweredAssumed Answered

Regarding STM32F207 Timers ISR

Question asked by verma.ruchi on Nov 26, 2014
Latest reply on Nov 27, 2014 by verma.ruchi
Hi, 


I am very new to 32 bit micro-controllers.I am using STM32f207VG controller.I want to use Timer2 to generate Interrupt every 1 ms.

Timer clock is set to 36MHz. I have written the following code for timer ISR.
My code is going into timer ISR and glowing the LED.But it think it is not coming back from Timer ISR.Because when the value of Trace couter is >1000 it should turn off the LED.But it is never happening.Please Find the code Below and let me know where i m doing wrong.

Thanks in advance :) !!


void Timer2Init();
int main(void)
{
  
  /* Clear WatchDog Registers */
  WatchDog_clear();
  /*configure Clock ; SystemCoreClock = 120000000 */
  SysTick_Config(SystemCoreClock / 1000);
  /*Initialise Watchdog Timer*/
  Watchdog_Init();
  /*Initialise the CPU clock*/
  CPU_initializeClocks();
  /*Initialise GPIO's ,UART's , LED's */
  CPU_initializeGPIO();
  CPU_initializeInterrupts();
  Timer2Init(); 
  TIM_Cmd(TIM2,ENABLE);
  while (1) 
  { 
    
  WatchDog_Reload(); //FeedinG Watcdog 

  if(traceCnt > 1000)
  {
    LedRed(OFF);
    TIM_Cmd(TIM2,DISABLE);
  }
  
  }//end while (1)  
} //end main()


void Timer2Init()
{
   TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
   NVIC_InitTypeDef   NVIC_InitStructure;
   TIM_DeInit(TIM2);
   
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
   
  TIM_TimeBaseStructure.TIM_Period = 0x8CA0;
  TIM_TimeBaseStructure.TIM_Prescaler = 2;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode =  TIM_CounterMode_Up;
  
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
 
  /* Enable TIM2 Interrupt channel */
  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  
  TIM_ITConfig(TIM2, TIM_IT_Update,ENABLE);
 
  
}
/*******************************************************************************
 * Function Name  : TIM2_IRQHandler
 * Description    : This function handles TIM2 global interrupt request.
 * Input          : None
 * Output         : None
 * Return         : None
 *******************************************************************************/
void TIM2_IRQHandler(void)
{
  if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
  {    
      traceCnt++;
      LedRed(ON);
    /* Clear CC4 Interrupt pending bit */
    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
  }
}

Outcomes