我做的一个板子上用STM32F103RET6的PB8的IO管脚来接收外部轻触按键输入的中断。我将这个PB8初始化并使能后运行,不去按轻触按键时发现程序总是不断的触发中断,使程序总是处于中断服务当中服务当中。下面是我的中断初始化和中断处理函数的代码,显示输出的计数器在不断的加一计数。这个PB8的管脚只连接了轻触按键,PB8通过10K电阻上拉到3.3V。我用示波器探了这个PB8也没发现有触发中断的脉冲产生,是一个平稳的3.3V。不知道出了什么问题,还望路过的大侠指点小弟。
void Exti_IOPort_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8);
EXTI_InitStructure.EXTI_Line =EXTI_Line8;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI9_5_IRQHandler(void)
{
unsigned short Itemp;
ITStatus ItState,FlagState;
ItState = EXTI_GetITStatus(EXTI_Line8);
FlagState = EXTI_GetFlagStatus(EXTI_Line8);
if((ItState != RESET) & (FlagState != RESET))
{
KEY2_NUM++;
EXTI_ClearITPendingBit(EXTI_Line8);
EXTI_ClearFlag(EXTI_Line8);
ShowString88(3, 0, "K2 On!Count:");
ShowCharNum(3, 12, KEY2_NUM);
}
for(Itemp=0;Itemp<25536;Itemp++) ;
} |