stm32 HAL计时器中断设置不起作用

时间:2018-06-19 14:19:33

标签: timer interrupt stm32f4

我正在使用STM32F4x核HAL库,并尝试设置计时器中断。 这是行不通的。这是计时器中断的设置:

 // Timer is configured to be triggered  every .05 secs. 

 __TIM4_CLK_ENABLE();

  Tim4Handle.Init.Prescaler = 16400;

  Tim4Handle.Init.CounterMode = TIM_COUNTERMODE_UP;

  Tim4Handle.Init.Period = 20;

  Tim4Handle.Instance = TIM4; 

  Tim4Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

  if ( HAL_TIM_Base_Init(&Tim4Handle) != HAL_OK )

   {

       Error_Handler();

    }

  TIM_SlaveConfigTypeDef sSlaveConfig;

  TIM_MasterConfigTypeDef sMasterConfig;

  sSlaveConfig.SlaveMode = TIM_SLAVEMODE_RESET;

  sSlaveConfig.InputTrigger = TIM_TS_ITR0;

  if (HAL_TIM_SlaveConfigSynchronization(&Tim4Handle, &sSlaveConfig) != HAL_OK)

 {

    Error_Handler();

  }

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

  if (HAL_TIMEx_MasterConfigSynchronization(&Tim4Handle, &sMasterConfig) != HAL_OK)

{

    Error_Handler();

 }  

HAL_TIM_Base_Start_IT(&Tim4Handle);
HAL_NVIC_SetPriority(TIM4_IRQn, 0, 1); 
HAL_NVIC_EnableIRQ(TIM4_IRQn);

这是我的中断例程(永远不会被调用):

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
   // send gpio signal to scope
}

请您帮我看看有什么问题吗?

0 个答案:

没有答案