|
EXTI总是不能发生中断,可能还是配置错误。。。
[复制链接]
采用PC12作为外部中断线输入引脚,连接到EXTI_Line0,如下配置: 1〉在RCC中使能了PC port 2〉在NVIC中使能了EXTI_Line0中断 //使能EXTI 0通道 NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); 3〉在GPIO配置函数中配置PC12为输入悬浮 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOC, &GPIO_InitStructure); 4〉在EXTI配置函数中 EXTI_InitTypeDef EXTI_InitStructure; //EXTI线绑定在PC12 GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource12);
/* Configure Key Button EXTI Line to generate an interrupt on falling edge */ EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure);
//Generate software interrupt: simulate a falling edge applied on Key Button EXTI line EXTI_GenerateSWInterrupt(EXTI_Line0); 5〉中断处理函数 void EXTI0_IRQHandler(void) { if(EXTI_GetITStatus(EXTI_Line0) != RESET) { /* Toggle GPIO_LED pin 6 */ //GPIO_WriteBit(GPIO_LED, GPIO_Pin_6, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_Pin_6))));
/* Clear the Key Button EXTI line pending bit */ EXTI_ClearITPendingBit(EXTI_Line0); } } 6〉PC12肯定是有脉冲输入的
但是为什么只在4〉处用软件产生一次中断后就再也不进中断了呢?
|
|