最近做了一个板子,F407,使用PA3作为TIM9输入捕获实验。无法进入中断,请各位大神看一下什么原因。
代码如下
void TIM9_CH2_Cap_Init(u16 arr,u16 psc)
{
TIM_ICInitTypeDef TIM9_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB2Periph_TIM9,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_TIM9);
TIM_TimeBaseStructure.TIM_Prescaler=psc;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period=arr;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM9,&TIM_TimeBaseStructure);
TIM9_ICInitStructure.TIM_Channel = TIM_Channel_2;
TIM9_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
TIM9_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
TIM9_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
TIM9_ICInitStructure.TIM_ICFilter = 0x00;
TIM_ICInit(TIM9, &TIM9_ICInitStructure);
TIM_ITConfig(TIM9,TIM_IT_Update|TIM_IT_CC2,ENABLE);
TIM_Cmd(TIM9,ENABLE );
NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_TIM9_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM1_BRK_TIM9_IRQHandler(void)
{
if(TIM_GetITStatus(TIM9,TIM_IT_Update))
{
if(kaishi)
num++;
}
if(TIM_GetITStatus(TIM9,TIM_IT_CC2))
{
if(kaishi==1)
{
kaishi=0;
flag=1;
val=TIM_GetCapture2(TIM9);
TIM_OC2PolarityConfig(TIM9,TIM_ICPolarity_Rising);
}
{
kaishi=1;
TIM_Cmd(TIM9,DISABLE );
TIM_SetCounter(TIM9,0);
TIM_Cmd(TIM9,ENABLE );
TIM_OC2PolarityConfig(TIM9,TIM_ICPolarity_Falling);
}
}
TIM_ClearITPendingBit(TIM9,TIM_IT_Update|TIM_IT_CC2);
}
TIM9_CH2_Cap_Init(0XFFFF,168-1);
while(1)
{
temp=num;
if(flag)
{
temp*=0XFFFF;
temp+=val;
printf("HIGH:%lld us
",temp);
flag=0;
val=0;
num=0;
kaishi=0;
}
}
现在就是中断函数就是进不去,实在找不到原因了 恳请帮助!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>