1、初始化TIM基本计数器参数
void MX_TIM2_Init(void)
{
TIM_ClockConfigTypeDef sClockSourceConfig= {0};
TIM_MasterConfigTypeDef sMasterConfig= {0};
htim2.Instance=TIM2;
htim2.Init.Prescaler= 36000-1;
htim2.Init.CounterMode=TIM_COUNTERMODE_UP;
htim2.Init.Period= 2000-1;
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();
}
}
2、HAL_TIM_Base_Init(&htim2)应用参数基本参数配置
HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
{/*Check the TIM handle allocation*/
if (htim ==NULL)
{returnHAL_ERROR;
}/*Check the parameters*/assert_param(IS_TIM_INSTANCE(htim->Instance));
assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));if (htim->State ==HAL_TIM_STATE_RESET)
{/*Allocate