如主题所示,,麻烦哪位大神帮我看看,,为什么总是检测不到呢???就这么点代码,,就是找不到原因啊,,或者谁给个例程我参考参看
void TIM_InitCapture(TIM_TypeDef* TIMx)
{
TIM_ICInitTypeDef TIM_ICInitCapture;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4 , ENABLE);
GPIOB->CRL &= ~0x0F000000; //  B.6浮空输入
TIM_DeInit(TIMx);
TIM_ICStructInit(&TIM_ICInitCapture);
TIM_ICInitCapture.TIM_Channel = TIM_Channel_1; //TIM4_CH1
TIM_ICInitCapture.TIM_ICPolarity = TIM_ICPolarity_BothEdge; //条边沿触发
TIM_ICInitCapture.TIM_ICSelection = TIM_ICSelection_DirectTI; //
TIM_ICInitCapture.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitCapture.TIM_ICFilter = 0x0;
TIM_ICInit(TIMx, &TIM_ICInitCapture);
TIM_PWMIConfig(TIMx, &TIM_ICInitCapture);
/* Select the TIM4 Input Trigger: TIM_TS_ITR0 */
TIM_SelectInputTrigger(TIMx, TIM_TS_ITR0);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIMx, TIM_SlaveMode_Reset);
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIMx, TIM_MasterSlaveMode_Enable);
/* Enable the CC1 Interrupt Request */
TIM_ITConfig(TIMx, TIM_IT_CC1, ENABLE); //TIM_IT_CC1是TIM捕获/比较中断源
TIM_ClearITPendingBit(TIM4, TIM_IT_CC1|TIM_IT_Update);
/* TIM enable counter */
TIM_Cmd(TIMx, ENABLE);
}
void TIM4_IRQHandler()
{
/* Clear TIM4 Capture compare interrupt pending bit */
if (TIM_GetITStatus(TIM4, TIM_IT_CC1) != RESET)//????1·??ú????????
{
GPIO_WriteBit(GPIOB, GPIO_Pin_0, (BitAction)
(1-GPIO_ReadOutputDataBit(GPIOB,GPIO_Pin_0)));
}
TIM_ClearITPendingBit(TIM4, TIM_IT_CC1);
}
TIM_NVIC_Configuration(TIM4_IRQn,2,1);
|