不想用回调函数就直接在中断函数里处理也可以。
void MX_TIM7_Init(void)
{
__HAL_RCC_TIM7_CLK_ENABLE();
TIM_MasterConfigTypeDef sMasterConfig = {0};
htim7.Instance = TIM7;
htim7.Init.Prescaler = (HAL_RCC_GetSysClockFreq()/1000000)-1; //设置分频
htim7.Init.CounterMode = TIM_COUNTERMODE_UP; //设置向上计数
htim7.Init.Period = 999;
htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; //打开自动重载
if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
{
Error_Handler();
}
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
if (HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig) != HAL_OK)
{
Error_Handler();
}
HAL_NVIC_SetPriority(TIM7_IRQn, 0, 0); //设置终端优先级和分组
HAL_NVIC_EnableIRQ(TIM7_IRQn); //开中断
// HAL_TIM_Base_Start_IT(&htim7);
}
void TIM7_IRQHandler(void) //中断函数
{
HAL_TIM_IRQHandler(&htim7); //中断标准清除并调用回调函数
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) //回调函数
{
static int16 cnt=0;
cnt++;
if(htim == &htim7)
{
if(cnt==350){
cnt=0;
flag=0;
}
// soft_timer_it_func();
}
}