I'm using STM32F030R8 @ 40MHz and TIM6. I want to wait for some time without blocking main function, so i used TIM6 - code below:
TIM6->CR1 |= TIM_CR1_ARPE | TIM_CR1_OPM;//auto-reload, one-pulse
TIM6->PSC = 4000-1;//100usec
TIM6->ARR = 5000-1; //500ms for test
TIM6->DIER |= TIM_DIER_UIE; //enable update interrupt
EXTI interrupt turns on the timer (TIM6->CR1 |= TIM_CR1_CEN). But after the first EXTI interrupt, first timer update interrupt is executing after 130us instead of 500ms. After the first interrupt everything works properly - I get 500ms delay.
EXTI interrupt code:
if(EXTI->PR & EXTI_PR_PR13)
TIM6->CR1 |= TIM_CR1_CEN;
GPIOA->BSRR = GPIO_BSRR_BS_5;
EXTI->PR |= EXTI_PR_PR13;
TIM6 interrupt code:
GPIOA->BSRR = GPIO_BSRR_BR_5;
TIM6->SR &= ~(TIM_SR_UIF);
Do you know what I'm doing wrong?