各位,我遇到一个很离奇的问题,我设置上升沿触发,但检测到一个外部中断时,其上升沿/下降沿都触发,我只需要上升沿触发,很奇怪,那位大侠指点下!
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); // 使能AFIO时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // GPIOB_11;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure PB8 as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOB,&GPIO_InitStructure);
}
继续配置NVIC
/**
* @brief Configures NVIC and Vector Table base location.
* @param None
* @retval : None
*/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the NVIC Preemption Priority Bits*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
配置EXTI ,把PB11连接到EXTI
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
/*connect PB11 to EXTI*/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource11);
/*Config EXTI11*/
EXTI_InitStructure.EXTI_Line = EXTI_Line11;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
在中断函数里面记得清除标志位
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line11)!= RESET)
{
EXTI_ClearITPendingBit(EXTI_Line11);
GPIO_SetBits(GPIOC, GPIO_Pin_5);//PC5连蜂鸣器,让蜂鸣器响
GPIO_SetBits(GPIOC, GPIO_Pin_6);//PC6连指示灯,让指示灯亮
Delayms(100); 延时100ms
}
}
在主函数里面蜂鸣器一直关着,指示灯灭,我PB11连接每中断一次,蜂鸣器响两次,指示灯亮两次。示波器查看中断信号很好,在上升沿时和下降沿时蜂鸣器都响,指示灯都亮,很郁闷。希望大侠指点下。 |