求助,使用TIM8_CH2(PC7口)作为捕获输入引脚,对外部输入上升沿进行输入捕获,一直进不来中断,请大虾们看看
void TIM8_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_ICInitTypeDef TIM_ICInitStruct;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8 , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/*使用TIM8_CH2(PC7口)作为捕获输入引脚*/
TIM_TimeBaseStructure.TIM_Period=0XFFFF;
TIM_TimeBaseStructure.TIM_Prescaler= 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up ;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0000;
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
TIM_ICInitStruct.TIM_Channel= TIM_Channel_2;
//TIM_ICInitStruct.TIM_ICPolarity=TIM_ICPolarity_BothEdge;
TIM_ICInitStruct.TIM_ICPolarity=TIM_ICPolarity_Rising;
//TIM_ICInitStruct.TIM_ICPolarity=TIM_ICPolarity_Falling;
TIM_ICInitStruct.TIM_ICPrescaler= TIM_ICPSC_DIV1;
TIM_ICInitStruct.TIM_ICSelection=TIM_ICSelection_DirectTI ;
TIM_ICInitStruct.TIM_ICFilter=0x0 ;
TIM_ICInit(TIM8, &TIM_ICInitStruct);
TIM_ClearFlag(TIM8, TIM_IT_CC2);
TIM_ITConfig(TIM8,TIM_IT_CC2,ENABLE);
TIM_Cmd(TIM8, ENABLE);
}
void TIM_NVIC_Configuration(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = TIM8_CC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} |