2022-02-24 07:34 PM
Hello everyone, I have been working with the stm32wb15cc for a few months and am having a weird issue. I believe I have set up TIM2 and it's interrupts properly and my TIM1 interrupts work but TIM2 interrupts are not being called. TIM2 clk speed is 4Mhz. Any insights would be appreciated!
I noticed nowhere in the the setup function is there a "HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);" or HAL_NVIC_EnableIRQ(TIM2_IRQn); but maybe HAL does it behind the scenes? It didn't work when I added it anyways lol.
I have set up the TIM2 Timer as follows:
The setup Code is shown below and in TIM_Setup and TIM_Setup_Code images.
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim2.Instance = TIM2;
htim2.Init.Prescaler = 4000;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 10000;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
Error_Handler();
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
Error_Handler();
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
Error_Handler();
2022-02-25 01:26 AM
Hello @CBada.1 ,
Thanks for your feedback,
Actually, the "HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0)" and HAL_NVIC_EnableIRQ(TIM2_IRQn) are generated in the HAL_TIM_Base_MspInit() function in stm32wbxx_hal_msp.c file.
And the HAL_TIM_IRQHandler(&htim2) is generated in TIM2_IRQHandler() in stm32wbxx_it.c file.
I hope this helps !
If your issue is solved, please close this post by clicking the "Select as Best" button. This will help other members of the community find this response more quickly :)
Thanks for your contribution and do not hesitate to raise any issue/ feedback.
Sara.
2022-02-25 07:00 AM
> I have called "HAL_TIM_Base_Start(&htim2);"
HAL_TIM_Base_Start doesn't enable update interrupts. If you want interrupts, call HAL_TIM_Base_Start_IT.