本帖最后由 Anthony_brave 于 2017-7-24 16:24 编辑
PB6上升沿和下降沿都触发中断。PF7上升沿和下降沿都正常
void EXTI_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure; /*¶¨òåò»¸öEXTI_InitTypeDef ààDíμĽá11ì壬Ãû×Ö½DEXTI_InitStructure*/
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//ía2¿ÖD¶Ï£¬Dèòaê1ÄüAFIOê±Öó
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOF,ENABLE);
//======================================================
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource6);
EXTI_InitStructure.EXTI_Line = EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//---------------------------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOF, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOF, GPIO_PinSource7);
EXTI_InitStructure.EXTI_Line = EXTI_Line7;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
问题已经解决,现将解决方案分享一下1、第一个问题是PB6设置的是上升沿/下降沿,结果上升沿和下降沿都触发中断。原因是:PB6处有个上拉,上拉电阻原来是100K,电阻值太大导致的,应该改为2K。
2、第二个问题是把PB6处的上拉去掉,设置下降沿触发没问题,但是设置上升沿触发,就不行。
原因:中断函数写的有问题。void EXTI9_5_IRQHandler(void)
{
unsigned char temp;
if(EXTI_GetITStatus(EXTI_Line7) != RESET)
{
EXTI_ClearFlag(EXTI_Line7);
if((GPIOF->IDR & 0x0080)==0) { return;}
else
{ xxxxxxxxxxxx; }
EXTI_ClearITPendingBit(EXTI_Line7);
}
if(EXTI_GetITStatus(EXTI_Line6) != RESET)
{
EXTI_ClearFlag(EXTI_Line6);
temp=(GPIOB->IDR & 0x0040)&0xff;
if(temp==0)
{
XXXXXXXXX;
}
EXTI_ClearITPendingBit(EXTI_Line6);
}
}
当上升沿触发时,中断函数里的
temp=(GPIOB->IDR & 0x0040)&0xff;
if(temp==1)
{ *****}
应改为
temp=(GPIOB->IDR & 0x0040)&0xff;
if(temp&0x0040)
{ *****}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>