所以,你能还初始化到正确的外部中断吗?!
正确的初始化函数如下:
void Hall_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//使能PORTA,PORTC时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //使能复用功能时钟
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //使能HALL所在的外部中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x1; //子优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
/* 配置Hall接口IO */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;//HALL信号检测端口
GPIO_InitStructure.GPIO_Mode =GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//清空中断标志
EXTI_ClearITPendingBit(EXTI_Line7); //清除中断标志位
EXTI_ClearITPendingBit(EXTI_Line8); //清除中断标志位
EXTI_ClearITPendingBit(EXTI_Line9); //清除中断标志位
//老老实实一行一行来
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource7 );
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource8 );
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource9 );
EXTI_InitStructure.EXTI_Line=EXTI_Line7 | EXTI_Line8 | EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
|