完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
如题。
我设置GPIOG 0-5一共6个按键做外部中断,5K电阻上拉到3.3V。现在的问题是按下其中一个按键时,除了该按键的中断响应以外,其他按键的中断有时候也被响应,求大师指导! 程序: void EXti_SetupNVIC(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0); /*Configureonebitforpreemptionpriority*/ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);// 1bitsforpre-emptionpriority //3bitsforsubpriority*/) /*EnabletheEXTI9_5Interrupt*/ NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init( NVIC_InitStructure); // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /*EnabletheEXTI15_10Interrupt*/ NVIC_InitStructure.NVIC_IRQChannel=EXTI1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init( NVIC_InitStructure); /*EnabletheEXTI15_10Interrupt*/ NVIC_InitStructure.NVIC_IRQChannel=EXTI2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init( NVIC_InitStructure); /*EnabletheEXTI15_10Interrupt*/ NVIC_InitStructure.NVIC_IRQChannel=EXTI3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init( NVIC_InitStructure); /*EnabletheEXTI15_10Interrupt*/ NVIC_InitStructure.NVIC_IRQChannel=EXTI4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init( NVIC_InitStructure); /*EnabletheEXTI15_10Interrupt*/ NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init( NVIC_InitStructure); } void EXTI_SetupGPIO(void) { GPIO_InitTypeDef GPIO_InitStructure;/* ¶¨ÒåÒ»¸öGPIO³õʼ»¯½á¹¹Ìå */ /*ConfigurePB9asinputfloating(EXTILine9)*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOG, GPIO_InitStructure); /*ConfigurePC13asinputfloating(EXTILine13)*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOG, GPIO_InitStructure); /*ConfigurePC13asinputfloating(EXTILine13)*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOG, GPIO_InitStructure); /*ConfigurePC13asinputfloating(EXTILine13)*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOG, GPIO_InitStructure); /*ConfigurePC13asinputfloating(EXTILine13)*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOG, GPIO_InitStructure); /*ConfigurePC13asinputfloating(EXTILine13)*/ GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOG, GPIO_InitStructure); } void EXTI_Configure(void) { EXTI_InitTypeDef EXTI_InitStructure; GPIO_EXTILineConfig(GPIO_PortSourceGPIOG,GPIO_PinSource0); 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); GPIO_EXTILineConfig(GPIO_PortSourceGPIOG,GPIO_PinSource1); EXTI_InitStructure.EXTI_Line=EXTI_Line1; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init( EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOG,GPIO_PinSource2); EXTI_InitStructure.EXTI_Line=EXTI_Line2; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init( EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOG,GPIO_PinSource3); EXTI_InitStructure.EXTI_Line=EXTI_Line3; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init( EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOG,GPIO_PinSource4); EXTI_InitStructure.EXTI_Line=EXTI_Line4; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init( EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOG,GPIO_PinSource5); EXTI_InitStructure.EXTI_Line=EXTI_Line5; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init( EXTI_InitStructure); } void EXTI_SETUP(void) { EXTI_Clock(); EXTI_SetupNVIC(); EXTI_SetupGPIO(); EXTI_Configure(); } |
|
相关推荐
1个回答
|
|
在STM32F103上设置6个外部按键中断时,出现相互干扰的问题可能是由于以下几个原因导致的:
1. 按键之间的物理接触:如果按键之间的距离过近,可能会导致按键之间的物理接触,从而触发其他按键的中断。解决方法是增加按键之间的距离,或者使用屏蔽线来减少干扰。 2. 按键去抖动处理不当:按键在按下和释放时,可能会产生抖动,导致中断误触发。为了解决这个问题,可以在程序中加入去抖动处理。一种简单的方法是使用软件去抖动,即在检测到按键按下后,延时一段时间(例如10ms)再次检测按键状态,如果状态仍然为按下,则认为按键按下有效。 3. 中断优先级配置不当:如果多个按键中断的优先级相同,可能会导致中断响应混乱。可以通过调整中断优先级来解决这个问题。在STM32中,可以使用NVIC_PriorityGroupConfig()函数来配置优先级组,然后使用NVIC_InitTypeDef结构体中的NVIC_IRQChannelPreemptionPriority和NVIC_IRQChannelSubPriority字段来设置每个中断的优先级。 4. 中断服务程序(ISR)设计不合理:如果ISR中处理按键中断的逻辑设计不合理,可能会导致其他按键的中断被错误地触发。确保ISR中只处理当前触发的按键中断,并且避免在ISR中执行过多的操作,以减少对其他中断的影响。 针对您提供的程序片段,我建议您首先检查按键之间的物理接触和去抖动处理。如果问题仍然存在,可以考虑调整中断优先级和优化ISR设计。 |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1627 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1550 浏览 1 评论
984 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
688 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1601 浏览 2 评论
1867浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
650浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
518浏览 3评论
536浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
506浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 20:20 , Processed in 0.679919 second(s), Total 49, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号