2018-10-16 03:29 AM
I want generate an event when the timer counter is at CCR1 register or ARR register.
But when the counter is enabled, the timer generates all events.
Can you help me?
This is the init routine
void init_timeout_timer22()
{
RCC->APB2ENR = RCC->APB2ENR | 0x20; //TIM22 Clock enable
LL_TIM_SetCounterMode(TIMER_TIMEOUT, LL_TIM_COUNTERMODE_UP);
LL_TIM_SetClockDivision(TIMER_TIMEOUT, LL_TIM_CLOCKDIVISION_DIV1); //Clock 32MHz
LL_TIM_SetPrescaler(TIMER_TIMEOUT, 32000);
LL_TIM_SetAutoReload(TIMER_TIMEOUT, 8000);
LL_TIM_SetCounter(TIMER_TIMEOUT, 0x0000);
LL_TIM_DisableIT_UPDATE(TIMER_TIMEOUT);
LL_TIM_DisableIT_CC1(TIMER_TIMEOUT);
LL_TIM_DisableIT_CC2(TIMER_TIMEOUT);
}
This is the routine that i call to set the limit and start counter
void enableToutI2cProtocolInt(int tout)
{
LL_TIM_DisableCounter(TIMER_TIMEOUT);
// Clear counter to make sure it starts from zero
LL_TIM_SetCounter(TIMER_TIMEOUT, 0);
LL_TIM_SetAutoReload(TIMER_TIMEOUT, tout);
//reset flag I2c timeout
startAlarmTimoutI2cIntProtocol();
// Configure ISR
LL_TIM_ClearFlag_CC1(TIMER_TIMEOUT);
LL_TIM_ClearFlag_UPDATE(TIMER_TIMEOUT);
LL_TIM_EnableIT_UPDATE(TIMER_TIMEOUT);
LL_TIM_EnableIT_CC1(TIMER_TIMEOUT);
LL_TIM_EnableCounter(TIMER_TIMEOUT);
NVIC_EnableIRQ(TIM22_IRQn);
}
2018-10-16 03:56 AM
Read out and check/post content of the timer registers just before you enable it.
Enable means TIMx_CR1.CEN=1?
JW
2018-10-16 03:56 AM
Read out and check/post content of the timer registers just before you enable it.
Enable means TIMx_CR1.CEN=1?
JW
2018-10-17 12:34 AM
I don't know why, but now i changed the init function and it's working
void init_timeout_timer22()
{
RCC->APB2ENR = RCC->APB2ENR | 0x20; //TIM22 Clock enable
LL_TIM_SetPrescaler(TIMER_TIMEOUT, 32000);
LL_TIM_GenerateEvent_UPDATE(TIMER_TIMEOUT);
LL_TIM_EnableIT_CC1(TIMER_TIMEOUT);
LL_TIM_SetUpdateSource(TIMER_TIMEOUT, LL_TIM_UPDATESOURCE_COUNTER);
LL_TIM_SetOnePulseMode(TIMER_TIMEOUT, LL_TIM_ONEPULSEMODE_SINGLE);
LL_TIM_DisableARRPreload(TIMER_TIMEOUT);
LL_TIM_SetTriggerOutput(TIMER_TIMEOUT, LL_TIM_TRGO_UPDATE);
NVIC_SetPriority(TIM22_IRQn, 1);
NVIC_DisableIRQ(TIM22_IRQn);
}
I tried to remove the GenerateEvent_Udate and it stop working fine. Maybe is it the reason?