cancel
Showing results for 
Search instead for 
Did you mean: 

Why on STM32L053, TIMER22 generates an update, CC1 and CC2 event when counter is enabled?

Damiano Balzani
Associate III

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);
}

3 REPLIES 3

Read out and check/post content of the timer registers just before you enable it.

Enable means TIMx_CR1.CEN=1?

JW

Read out and check/post content of the timer registers just before you enable it.

Enable means TIMx_CR1.CEN=1?

JW

Damiano Balzani
Associate III

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?