cancel
Showing results for 
Search instead for 
Did you mean: 

CNT value interrupt

hdemi.1
Associate III

I want to generete interrupt for specific value of TIM->CNT

TIM1->DIER |= TIM_IT_CC1;

TIM1->CCR1 = myVal;

I use only above.

if(TIM_GetITStatus(TIM1,TIM_IT_CC1) != RESET){

//when interrupt generete here ,CCR1 is not equal my value

}

 I'm so confused why am I doing wrong?

6 REPLIES 6
gbm
Lead III

The bit in DIER is called TIM_DIER_CC1IE, and the flag TIM_SR_CC1IF, so:

TIM1->DIER |= TIM_DIER_CC1IE;

if (TIM1->SR & TIM_SR_CC1IF) ...

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
hdemi.1
Associate III

I write code like that. It always generete interrupt despite clear the flag and interrupt source.

if(Counter == .DelayloopCount){

TIM1->CCR1 = DelayOverFlow ; //this code not always running

TIM1->DIER |= TIM_DIER_CC1IE;

}

if(TIM1->SR & TIM_SR_CC1IF){

//doing something

TIM1->DIER &= (uint16_t)~TIM_DIER_CC1IE;

TIM1->SR = (uint16_t)~TIM_SR_CC1IF; //clear flag }

hdemi.1
Associate III

I write code like that. It always generete interrupt despite clear the flag and interrupt source.

if(Counter == .DelayloopCount){

TIM1->CCR1 = DelayOverFlow ; //this code not always running

TIM1->DIER |= TIM_DIER_CC1IE;

}

if(TIM1->SR & TIM_SR_CC1IF){

//doing something

TIM1->DIER &= (uint16_t)~TIM_DIER_CC1IE;

gbm
Lead III

If enabled, the timer should generate an interrupt during every period, so I assume it's normal.

What other TIM1 interrupts are enabled? Use the debugger to check the values of DIER and SR registers while in ISR.

In the ISR, clear the CC1IF flag immediately after checking for it, NOT at the end of ISR.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
hdemi.1
Associate III

SR value is 0x025F when works TIM1->CR1 |= TIM_CR1_CEN I can not clean this flag

with this way :

TIM->SR &= (uint16_t)(~(TIM_SR_CC1IF | TIM_SR_CC2IF | TIM_SR_CC3IF |TIM_SR_CC4IF));

gbm
Lead III

Do not use &= to clear the flags in SR - this leads to errors. The flags are cleared but if the timer is running, it sets the flags again.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice