我想使用PB8引脚作为中断的输入口,但是初始化后死活进不去中断,求大神们指教。
void PB8_IrDA_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure; // 定义一个EXTI结构体变量
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOB, ENABLE); // 使能IO复用功能,使用中断功能重要!!!
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //PB8为输入口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //速度为50MHz
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_Init(GPIOB,&GPIO_InitStructure);
EXTI_ClearITPendingBit(EXTI_Line8);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource8); //PB8为中断
EXTI_InitStructure.EXTI_Line = EXTI_Line8;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //中断模式为外部中断模式
EXTI_InitStructure.EXTI_Trigger = EXTI_TriggerFalling; //下降沿触
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能中断线
EXTI_Init( &EXTI_InitStructure); //根据参数初始化中断寄存器
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //设定中断源为PB8
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //中断占优先级为1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //副优先级为3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能中断
NVIC_Init( &NVIC_InitStructure); //根据参数初始化中断寄存器
}
//
//
//
void EXTI9_5_IRQHandler(void) // IR引脚为PinB_8
{
if (RESET != EXTI_GetITStatus(EXTI_Line8) ) // 判断是否发生中断,发生则中断标志置1
{
IsEvnt_IrDA =TRUE;
EXTI_ClearITPendingBit(EXTI_Line8);
}
}
|