AnsweredAssumed Answered

STM32F0 Timer interrupt problem

Question asked by robert.o on May 11, 2018
Latest reply on May 13, 2018 by robert.o

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
NVIC_EnableIRQ(TIM6_IRQn);

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:

void EXTI4_15_IRQHandler(void)
{
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:

void TIM6_IRQHandler(void)
{
GPIOA->BSRR = GPIO_BSRR_BR_5;
TIM6->SR &= ~(TIM_SR_UIF);
}

Do you know what I'm doing wrong?

Outcomes