我同时配置了外部中断0和13,中断13一直进不去,进入调试模式发现EXTI_PR的PR13一直为1,我应该怎么做才能正常运行中断程序,这是我的代码:
/*********************main.c******************************/
#include "stm32f10x.h"
#include "Led.h"
#include "sk_exti.h"
int main(void)
{
Led_Config();
LED1(ON);
EXTI_Config();
while(1)
{
}
}
/*********************sk_exti.c***************************************/
#include "sk_exti.h"
void EXTI_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | \
RCC_APB2Periph_AFIO, ENABLE); //´ò¿ªGPIOA,GPIOC,AFIOʱÖÓ
/* É趨GPIOA_Pin0ºÍGPIOC_Pin_13ΪÉÏÀÊäÈëģʽ */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
static void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //ÖжϷÖ×é1
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //ÅäÖÃÍⲿÖжÏ1µÄÖжÏÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //ÅäÖÃÍⲿÖжÏ13µÄÖжÏÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); //½«GPIOA_Pin_0ÓëÍⲿÖжÏ1ͨµÀÁ¬½Ó
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource13); //½«GPIOC_Pin_13ÓëÍⲿÖжÏ13ͨµÀÁ¬½Ó
NVIC_Config();
EXTI_InitStructure.EXTI_Line = EXTI_Line0 | EXTI_Line13; //¿ªÍⲿÖжÏ0ºÍ13µÄÖжÏ
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //ÉèÖÃΪÖжÏģʽ
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //ϽµÑØ´¥·¢
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
/**************************中断程序***************************/
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_4, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_4)));
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
{
LED3(ON);
EXTI_ClearITPendingBit(EXTI_Line13);
}
}
/****************Led.c***************/
#include "Led.h"
void Led_Config(void)
{
/*ÅäÖÃGPIOB_Pin_0, GPIOC_Pin_3,4 */
GPIO_InitTypeDef GPIO_InitStrucute;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStrucute.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStrucute.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStrucute.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStrucute);
GPIO_InitStrucute.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
// GPIO_InitStrucute.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_InitStrucute.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStrucute);
GPIO_SetBits(GPIOB, GPIO_Pin_0); //¹Ø±ÕLED1
GPIO_SetBits(GPIOC, GPIO_Pin_3 | GPIO_Pin_4); //¹Ø±ÕLED2, LED3
}
|