AnsweredAssumed Answered

Timer Problem

Question asked by PeterLup2 on Feb 28, 2015
Latest reply on Mar 1, 2015 by Clive One
Hi,

I'm having a problem with timer 2 on the stm32f407 discovery board.
I want a frequency of 1khz but I can only get 1ms before entering, for the first time, in the ISR. After that, I get Stuck on the ISR and because i can not pass the if statment, on the debugger. I can see SR register (debugger) but it's blocked for writing, i believe.

Any help would be appreciated, thanks.

-------------------------------------------------------------------------------------------------------

void INIT_TIM2(){
     
     TIM_TimeBaseInitTypeDef TIM2_Init;
     NVIC_InitTypeDef NVIC_InitStructure;
          
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
     
     //Configure Timer 2 to Freq = 1khz
     TIM2_Init.TIM_CounterMode = TIM_CounterMode_Up;
     TIM2_Init.TIM_RepetitionCounter = 0x00;
     TIM2_Init.TIM_ClockDivision = TIM_CKD_DIV2;
     TIM2_Init.TIM_Prescaler = 84-1;
     TIM2_Init.TIM_Period = 1000-1;
     
     TIM_TimeBaseInit(TIM2, &TIM2_Init);
     TIM2->SR &= 0xfffe;
     
     //Confiruge Timer2 interrupt
     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);
     
     TIM_Cmd(TIM2, ENABLE); // Enable Timer2
     //TIM2->CR1 |= 0x001; 
}


void TIM2_IRQHandler (void) {
     
      if ((TIM1->SR & 0x0001) != 0)
    {
        TIM1->SR &= ~(1<<0);
          }
}


int main(){
     
     char* text[100];
     INIT_TIM2();


     while(1);
     
}

Outcomes