2015-11-19 07:24 PM
I use TIM2. I configure device using this code
int main()
{
...
TIM2->CR1 = 0;
TIM2->EGR = 0;
TIM2->PSC = 59;
TIM2->ARR = 4999;
TIM2->DIER |= TIM_DIER_UIE;
TIM2->SR = 0;
NVIC_SetPriority(TIM2_IRQn,5);</span>
NVIC_EnableIRQ(TIM2_IRQn);</span>
GPIOD->BSRR = GPIO_BSRR_BS15;
TIM2->CR1 |= TIM_CR1_CEN;
while(1);
return 0;
}
extern ''C'' void TIM2_IRQHandler()
{
if((TIM2->SR & TIM_SR_UIF) > 0)
{
TIM2->SR &= ~TIM_SR_UIF;
GPIOD->BSRR = GPIO_BSRR_BR15;
}
}
APB1 timers speed is 60MHz.
(TIM2->CR1 |= TIM_CR1_CEN;) starts the timer
Expecting: the interrupt is fired up after 4999 tics at first time and then every 4999 tics.
Actual: the interrupt is fired up after 200 tics at first time and then every 4999 tics.
I set a breakpoint on TIM2_IRQHandler. The TIM2 struct is:
TIM2->CR = 0x0001
TIM2->DIER = 0x0001;
TIM2->ARR = 4999
TIM2->PSC = 59
TIM2->CNT = 0x00C8
TIM2->SR = 0x
0000001
FWhats the reason of this behavior?
Thank you. #stm32 #interrupt #timer