AnsweredAssumed Answered

STM32F103 TIM2 configuration

Question asked by nowrozi.daniel on May 6, 2015
Latest reply on May 7, 2015 by Clive One
Hi there..!

sorry if my question seems duplicate but I dont know what's wrong, I want to set TIM2 interrupt to 1 ms without success.

this is my clock configuration
#define __RCC_CR_VAL               0x01010082
#define __RCC_CFGR_VAL             0x00118402
#define __HSE                      12000000
 
void ClockSetup (void) {
  /* Clock Configuration*/
 
  RCC->CFGR = __RCC_CFGR_VAL;                        // set clock configuration register
  RCC->CR   = __RCC_CR_VAL;                          // set clock control register
 
  if (__RCC_CR_VAL & RCC_CR_HSEON) {                 // if HSE enabled
    while ((RCC->CR & RCC_CR_HSERDY) == 0);          // Wait for HSERDY = 1 (HSE is ready)
  }
 
  if (__RCC_CR_VAL & RCC_CR_PLLON) {                 // if PLL enabled
    while ((RCC->CR & RCC_CR_PLLRDY) == 0);          // Wait for PLLRDY = 1 (PLL is ready)
  }
 
  /* Wait till SYSCLK is stabilized (depending on selected clock) */
  while ((RCC->CFGR & RCC_CFGR_SWS) != ((__RCC_CFGR_VAL<<2) & RCC_CFGR_SWS));
} // end of ClockSetup

and this is my TIM2 initialization
void vTIMER_InitRCC(void)
{
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
}
void vTIMER_InitGeneral(void)
{
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 
  /* Time Base configuration 1ms based on HCLK 72MHz using HSE * 6 */
  TIM_TimeBaseStructure.TIM_Prescaler = 7199;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = 9;
  TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
 
  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);    /* Enable the TIM Update Interrupt */
  TIM_Cmd(TIM2, ENABLE);                        /* TIM counter enable */
  NVIC_EnableIRQ(TIM2_IRQn);                    /* Enable TIM2 interrupt */
}
 
void TIM2_IRQHandler(void)
{
  TIM_ClearITPendingBit(TIM2, TIM_IT_Update);      /* Clear the Update pending bit */
  timer1ms++;
  /* Periodic cyclic function call */
    if(timer1ms == 1000)
    {
            timer1ms = 0;
            timer1s++;
    }
}

and this is my code for turning on LED
... //initializations
while(1)
  {
            if(timer1s == 1)
            {
                    //readDoorStatus(I2C1, 13);
                    timer1s++;
                    STM_EVAL_LEDOn(LED1);
            }
            else if(timer1s == 11)
            {
                    STM_EVAL_LEDOff(LED1);
                    timer1s = 0;
            }   
  }
 
...

but my LED is ON only for 7 second??

Outcomes