2023-01-15 01:15 AM
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?
2023-01-15 02:05 AM
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) ...
2023-01-15 04:56 AM
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 }
2023-01-15 04:57 AM
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;
2023-01-15 05:27 AM
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.
2023-01-15 06:04 AM
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));
2023-01-15 08:01 AM
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.