stm32如何配置两个触发沿不同的外部中断线? 5
现在我将PC0,PC1分别作为外部中断线0和1的入口,EXTI0设置上升沿触发,PC1设置下降沿触发,外部中断程序如下,为什么我发现只能进到外部中断1中而不能进到外部中断...
现在我将PC0, PC1分别作为外部中断线0和1的入口,EXTI0设置上升沿触发,PC1设置下降沿触发,外部中断程序如下,为什么我发现只能进到外部中断1中而不能进到外部中断0中,不知是怎么回事?
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //抢占优先级0位,响应优先级4位
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //外部中断线0中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //主优先级为0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //从优先级为0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道使能
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; //外部中断线1中断 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //允许中断
NVIC_Init(&NVIC_InitStructure);
}
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* =======================开启时钟================*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE); // 使能APB2外设GPIOC时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/*---------------------外部中断线0的配置-------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //配置PC0为外部中断
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;// 下拉输入 //GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource0); //EXTI0
EXTI_DeInit(); //将EXIT寄存器重设置为缺省值
EXTI_InitStructure.EXTI_Line = EXTI_Line0 ; //中断线
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt ; //中断模式
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //上升沿
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能
EXTI_Init(&EXTI_InitStructure); //初始化
EXTI_ClearITPendingBit(EXTI_Line0);
/*---------------------外部中断线1的配置-------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //配置PC0为外部中断
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;// 上拉输入 //GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource1); //EXTI1
EXTI_DeInit(); //将EXIT寄存器重设置为缺省值
EXTI_InitStructure.EXTI_Line = EXTI_Line1 ; //中断线
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt ; //中断模式
EXTI_InitStructure.EXTI_Trigger =EXTI_Trigger_Falling; //下降沿
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearITPendingBit(EXTI_Line1);
} 展开
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //抢占优先级0位,响应优先级4位
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //外部中断线0中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //主优先级为0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //从优先级为0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //通道使能
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; //外部中断线1中断 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //响应优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //允许中断
NVIC_Init(&NVIC_InitStructure);
}
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* =======================开启时钟================*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE); // 使能APB2外设GPIOC时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/*---------------------外部中断线0的配置-------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //配置PC0为外部中断
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;// 下拉输入 //GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource0); //EXTI0
EXTI_DeInit(); //将EXIT寄存器重设置为缺省值
EXTI_InitStructure.EXTI_Line = EXTI_Line0 ; //中断线
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt ; //中断模式
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //上升沿
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能
EXTI_Init(&EXTI_InitStructure); //初始化
EXTI_ClearITPendingBit(EXTI_Line0);
/*---------------------外部中断线1的配置-------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //配置PC0为外部中断
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;// 上拉输入 //GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource1); //EXTI1
EXTI_DeInit(); //将EXIT寄存器重设置为缺省值
EXTI_InitStructure.EXTI_Line = EXTI_Line1 ; //中断线
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt ; //中断模式
EXTI_InitStructure.EXTI_Trigger =EXTI_Trigger_Falling; //下降沿
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearITPendingBit(EXTI_Line1);
} 展开
若以下回答无法解决问题,邀请你更新回答
2个回答
展开全部
需要帮你做设计吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询