2023-12-28 04:16 PM - last edited on 2023-12-29 07:23 AM by SofLit
Hi, I have use MX to generate code for this timer.
The generated code is as follows:
static void MX_TIM2_Init(void)
{
/* USER CODE BEGIN TIM2_Init 0 */
/* USER CODE END TIM2_Init 0 */
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
TIM_MasterConfigTypeDef sMasterConfig = {0};
/* USER CODE BEGIN TIM2_Init 1 */
/* USER CODE END TIM2_Init 1 */
htim2.Instance = TIM2;
htim2.Init.Prescaler = 0;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 65535;
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_ENABLE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM2_Init 2 */
/* USER CODE END TIM2_Init 2 */
}
I can't get to see an interrupt happening, neither I see the TIM2->CNT register changing.
What can possibly be wrong?
Thanks,
Solved! Go to Solution.
2023-12-28 04:23 PM
Clock on bus not enabled?
Timer not started?
Check RCC and TIM2 register content, or dump out for review
2023-12-28 04:23 PM
Clock on bus not enabled?
Timer not started?
Check RCC and TIM2 register content, or dump out for review
2023-12-29 06:08 AM
It was an IDE problem. For some reason, it was keeping garbage on the registers, I restarted the computer and everything works.
Sorry for creating this post before trying to restart my PC.