使用stm32中断函数,配置按键分别为PA0,PC13,PA8,PD3。进行如下配置之后,发现PA0和PD3按键可以正常工作,PA8和PC13不但不能正常使用,一旦按过之后,连PA0和PD3也不能正常工作了。中断向量5-9是共用一个,10-15是共用一个的,所以在5-9中我要具体使用哪个是否需要另行配置?
中断配置如下:
void EXTIX_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
KEY_Init(); // °′¼ü¶Ë¿ú3õê¼»ˉ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); //ê1Äü¸′óÃ1|Äüê±Öó
//GPIOC.13 ÖD¶ÏÏßòÔ¼°ÖD¶Ï3õê¼»ˉÅäÖà ϽμÑØ′¥·¢
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13);
EXTI_InitStructure.EXTI_Line=EXTI_Line13; //KEY2
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); //¸ù¾YEXTI_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèEXTI¼Ä′æÆ÷
//GPIOD.3 ÖD¶ÏÏßòÔ¼°ÖD¶Ï3õê¼»ˉÅäÖà ϽμÑØ′¥·¢ //KEY1
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD,GPIO_PinSource3);
EXTI_InitStructure.EXTI_Line=EXTI_Line3;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_InitStructure); //¸ù¾YEXTI_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèEXTI¼Ä′æÆ÷
//GPIOA.0 ÖD¶ÏÏßòÔ¼°ÖD¶Ï3õê¼»ˉÅäÖà ϽμÑØ′¥·¢ PA0 WK_UP
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
EXTI_InitStructure.EXTI_Line=EXTI_Line0;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_InitStructure); //¸ù¾YEXTI_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèEXTI¼Ä′æÆ÷
// PA8
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource8);
EXTI_InitStructure.EXTI_Line=EXTI_Line8;
EXTI_Init(&EXTI_InitStructure); //¸ù¾YEXTI_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèEXTI¼Ä′æÆ÷
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //ê1Äü°′¼üWK_UPËùÔúμÄía2¿ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //ÇàÕ¼óÅÏ輶2£¬
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03; //×óóÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //ê1Äü°′¼üKEY2ËùÔúμÄía2¿ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //ÇàÕ¼óÅÏ輶2£¬
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //×óóÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //ê1Äü°′¼üKEY1ËùÔúμÄía2¿ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //ÇàÕ¼óÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; //×óóÅÏ輶1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn; //ê1Äü°′¼üKEY0ËùÔúμÄía2¿ÖD¶Ïí¨μà
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //ÇàÕ¼óÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00; //×óóÅÏ輶0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //ê1Äüía2¿ÖD¶Ïí¨μà
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
}
//ía2¿ÖD¶Ï0·tÎñ3ìDò
void EXTI0_IRQHandler(void)
{
delay_ms(10);//Ïû¶¶
if(KEY0==0) //WK_UP°′¼ü
{
led2=!led2;
}
EXTI_ClearITPendingBit(EXTI_Line0); //Çå3yLINE0éÏμÄÖD¶Ï±ê־λ
}
//ía2¿ÖD¶Ï2·tÎñ3ìDò
void EXTI3_IRQHandler(void)
{
delay_ms(10);//Ïû¶¶
if(KEY3==0) //°′¼üKEY2
{
led0=!led0;
}
EXTI_ClearITPendingBit(EXTI_Line3); //Çå3yLINE2éÏμÄÖD¶Ï±ê־λ
}
//ía2¿ÖD¶Ï8·tÎñ3ìDò
void EXTI8_IRQHandler(void)
{
delay_ms(10);//Ïû¶¶
if(KEY2==0) //°′¼üKEY1
{
led1=!led1;
}
EXTI_ClearITPendingBit(EXTI_Line8); //Çå3yLINE8éÏμÄÖD¶Ï±ê־λ
}
void EXTI13_IRQHandler(void)
{
delay_ms(10);//Ïû¶¶
if(KEY1==0) //°′¼üKEY0
{
led0=!led0;
led1=!led1;
}
EXTI_ClearITPendingBit(EXTI_Line13); //Çå3yLINE4éÏμÄÖD¶Ï±ê־λ
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
void EXTI13_IRQHandler(void)
这两个中断入口函数看一下!
一周热门 更多>