各位: 今天用stm32f103c8遇到一个奇怪的问题,我用pb1和5两个外部引脚做外部中断,都是上升沿触发。但是使能中断后,pb5一直进中断,挂起标志清了之后不知道在哪由置1了 不知道有没有同学遇到相同的问题。 下面是我的代码: //初始化代码: GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; // GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); // GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource1); GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource5); // EXTI_InitStructure.EXTI_Line = EXTI_Line1; // EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; // EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; // EXTI_InitStructure.EXTI_LineCmd = ENABLE; // EXTI_Init(&EXTI_InitStructure); EXTI_InitStructure.EXTI_Line = EXTI_Line5; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_GenerateSWInterrupt(EXTI_Line5); // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; // NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // NVIC_Init(&NVIC_InitStructure); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //中断服务函数: void EXTI9_5_IRQHandler(void) { EXTI->IMR &= ~EXTI_Line5; EXTI_ClearITPendingBit(EXTI_Line5); EXTI->IMR |= EXTI_Line5; } 终端服务函数中关中断和清标志位都是对的,但是出来之后挂起标志就又置1了。 |
真的清除了,而且真的外部没有触发。
我在内存里能看到,进入中断函数后先关中断,然后清标志,然后再开中断。
外部引脚一直是低电平,我设置的是上升沿触发,也没问题啊。
if(EXTI_GetITStatus(EXTI_Line9) != RESET)
{
/* Toggle LED2 */
STM_EVAL_LEDToggle(LED2);
/* Clear the EXTI line 9 pending bit */
EXTI_ClearITPendingBit(EXTI_Line9);
}
STM32F030 PB9和PB5配置为中断输入,没信号也老是进PB9中断,我在中断函数里加了一条将一个空闲IO口翻转指令,测试中断10uS左右进入一次。