请问这份代码有问题吗,卡在输入捕获初始化,跑不起来
void Input_Capture_Init(u16 arr, u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure = {0};
TIM_ICInitTypeDef TIM_ICInitStructure = {0};
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure = {0};
NVIC_InitTypeDef NVIC_InitStructure = {0};
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB, GPIO_Pin_6);
TIM_TimeBaseInitStructure.TIM_Period = 0xFFFF;
TIM_TimeBaseInitStructure.TIM_Prescaler = 48000 - 1;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0x00;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0x00;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInit(TIM4, &TIM_ICInitStructure);
// TIM_PWMIConfig(TIM4, &TIM_ICInitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1);
// TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Reset);
// TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);
TIM_ITConfig(TIM4, TIM_IT_Update|TIM_IT_CC1 , ENABLE);
TIM_Cmd(TIM4, ENABLE);
}
void TIM4_IRQnHandler (void)
{
printf("111\n");
if (TIM_GetITStatus(TIM4,TIM_IT_CC1) != RESET) //检查TIM5更新中断发生与否
{
printf("222\n");
}
TIM_ClearITPendingBit(TIM4,TIM_IT_CC1|TIM_IT_Update); //清除中断标志位
}