请教各路大神,小弟在用定时器输入捕获时,一直无法进入中断。以下为TIM1的通道2的寄存器配置。
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
static void TIM1_GPIO_Config(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
static void TIM1_IC_Config(void)
{
TIM_ICInitTypeDef TIM_ICInitStructure;
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM_ICInitStructure.TIM_ICFilter = 0;
TIM_ICInit(TIM1,&TIM_ICInitStructure);
TIM_ClearFlag(TIM1, TIM_FLAG_CC2);
TIM_Cmd(TIM1, ENABLE);
TIM_ITConfig(TIM1, TIM_IT_CC2, ENABLE);
}
static void NVIC_TIM1_IC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* enabling interrupt */
NVIC_InitStructure.NVIC_IRQChannel=TIM1_CC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
中断处理函数,
/**
* @brief This function handles TIM1 capture compare interrupt request.
* @param None
* @retval None
*/
void TIM1_CC_IRQHandler(void)
{
if(TIM_GetITStatus(TIM1,TIM_IT_CC2)!= RESET)
{
TIM_ClearITPendingBit(TIM1, TIM_IT_CC2);
}
}
PB14用作TIM1的通道2,输入峰峰值为2.9V的脉冲,一直无法进入中断,烦请各路大神指点。小弟50分奉上。
|