cancel
Showing results for 
Search instead for 
Did you mean: 

stm32cube Timer TIM2 Base IT : Callback immediatly

Posted on March 05, 2015 at 14:53

Hi,

I generated a project with stm32cube and I set timer TIM2 with follow conf, when I call HAL_TIM_Base_Start_IT the callback is called immediatly and not after a cycle ( as I expect).

P.S. After firts callback it's works fine (cycling with configured period)

MCU is STM32F207

void MX_TIM2_Init(void)

{

  TIM_ClockConfigTypeDef sClockSourceConfig;

  TIM_MasterConfigTypeDef sMasterConfig;

  htim2.Instance = TIM2;

  htim2.Init.Prescaler = 60000;

  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;

  htim2.Init.Period = 10;

  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

  HAL_TIM_Base_Init(&htim2);

  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

  HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

  HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig);

}

#stm32f2 #timer #stm32cube
4 REPLIES 4
Posted on March 05, 2015 at 16:56

as I expect

Update = transition to zero count, see also reset
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 06, 2015 at 10:38

Thanks for your quickly reply.

Sorry I don't understand very well the ans. Can you explain me?

I see another thing during my test, under first callback(immediatly callback I mean) if I use HAL_TIM_Base_Stop() into the callback  it doesn't work and I must use it on main{} function, after this if I use HAL_TIM_Base_Stop() into the callback during runtime operation it's works fine and stop htim->Instance.CNT

Nickname1997_O
Associate II
Posted on March 06, 2015 at 17:13

Hello Marco

At the end of the timer initialization procedure, an update event is sent. So an Update IT is pending.

I would suggest you to clear the Timer status register before calling HAL_TIM_Base_Start_IT (...)

hope this helps

Regards

Posted on March 09, 2015 at 09:31

Thank you very much for your advice, now I try to clean pending bit on init.

Best Regards