求助:STM32外部中断进不去啊 | 回复数:5,点击数:196 |
【楼主位】 panda1988 积分:28 派别: 等级:------ 来自: | 我今天玩STM32外部中断,玩了一天了还是进不去中断,现在把程序挂上来请大家帮我看看哪儿出问题了? 我用的是Keil编译器 LED1接PD8,LED2接PD9,正常的程序是LED1和LED2交替闪烁,无限循环;LED3接PD10,LED4接PD11,进入中断服务程序时LED3,LED4交替闪烁10次 可当我下载完程序时,STM32就直接进入中断先执行了一次,在回到主函数,正常执行主函数。当我触发中断的时候,却进不去?这是为什么呢?是不是我触发的方式不对?程序中配的是上升沿触发外部中断,我是用一个按键控制触发的,不论键的另一边接接高电平还是低电平都不能进入中断,哎!郁闷啊!!请大家帮我看看。先谢谢各位啦! 下边是主文件: main.c /* Includes ------------------------------------------------------------------*/ #include "stm32f10x_lib.h" #include "Clock.h"//时钟函数是正确的,因为主函数都能正常执行,中断服务函数也能正确执行,就是执行的时间不对 /* Private function prototypes -----------------------------------------------*/ void RCC_Configuration(void); //时钟配置 void NVIC_Configuration(void);//中断向量表和优先级设定 void GPIO_Configuartion(void);//端口模式配置 void Exti_Configuartion(void);//外部中断模式配置 void Delay(vu32 nCount);//延时函数 /* Private functions ---------------------------------------------------------*/ /******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { RCC_Configuration(); //配置时钟 NVIC_Configuration(); GPIO_Configuartion(); Exti_Configuartion(); while (1) { Delay(0xffffff); GPIO_ResetBits(GPIOD, GPIO_Pin_8 );//点亮led GPIO_SetBits(GPIOD, GPIO_Pin_9);//熄灭led Delay(0xffffff);//Dealy_Systick(1000); GPIO_ResetBits(GPIOD, GPIO_Pin_9 );//点亮led GPIO_SetBits(GPIOD, GPIO_Pin_8);//熄灭led } } /******************************************************************************* * Function Name : NVIC_Configuration * Description : Configures Vector Table base location. * Input : None * Output : None * Return : None *******************************************************************************/ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); //中断向量存储在FlASh区 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//选择中断优先级分组1 NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQChannel;//外部中断 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); } void GPIO_Configuartion(void) { GPIO_InitTypeDef GPIO_InitStructure; //LED控制端口 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);//打开用到的gpiod时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;//选择要配置的端口 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//配置为推免输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//转换速度 GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化gpio GPIO_ResetBits(GPIOD, GPIO_Pin_8 | GPIO_Pin_9|GPIO_Pin_10 | GPIO_Pin_11); //先复位 //中断控制端口 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//打开用到的gpiob时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;//选择要配置的端口 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//配置为浮空输入 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//转换速度 GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化gpio } /******************************************************************************* * Function Name : Exti_Configuration * Description : 配置外部事件, * Input : None * Output : None * Return : None *******************************************************************************/ void Exti_Configuartion(void) { EXTI_InitTypeDef EXTI_InitStructure; GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource6); //将PB6配置为EXTI Line6 EXTI_InitStructure.EXTI_Line=EXTI_Line6; EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure); EXTI_GenerateSWInterrupt(EXTI_Line6); } /******************************************************************************* * Function Name : Delay * Description : Inserts a delay time. * Input : nCount: specifies the delay time length. * Output : None * Return : None *******************************************************************************/ void Delay(vu32 nCount) { for(; nCount != 0; nCount--); } 中断服务函数:这个函数执行没问题,主要是触发不了中断和刚开始就进入中断 stm32f10x_it.c /* Includes ------------------------------------------------------------------*/ #include "stm32f10x_it.h" extern void Delay(vu32 nCount);//延时函数声明,这没问题 void EXTI9_5_IRQHandler(void) { int i; if(EXTI_GetITStatus(EXTI_Line6)!=RESET) { for(i=0;i<10;i++) { Delay(0xffffff); GPIO_ResetBits(GPIOD, GPIO_Pin_10 );//点亮led GPIO_SetBits(GPIOD, GPIO_Pin_11);//熄灭led Delay(0xffffff);//Dealy_Systick(1000); GPIO_ResetBits(GPIOD, GPIO_Pin_11 );//点亮led GPIO_SetBits(GPIOD, GPIO_Pin_10);//熄灭led EXTI_ClearITPendingBit(EXTI_Line6); } } } 本贴被 panda1988 编辑过,最后修改时间:2010-05-01,22:30:04. | ||
![]() |
![]() ![]() ![]() ![]() | ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
【1楼】 panda1988 积分:28 派别: 等级:------ 来自: | 怎么没人啊?顶! | ||
![]() |
![]() ![]() ![]() ![]() | ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
【2楼】 panda1988 积分:28 派别: 等级:------ 来自: | 我刚才把软件中断关了,//EXTI_GenerateSWInterrupt(EXTI_Line6); 开机上电就不进入中断了,但硬件中断还是进不去! | ||
![]() |
![]() ![]() ![]() ![]() | ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
【3楼】 foxsports ![]() 积分:259 派别: 等级:------ 来自:辽宁·鞍山 QQ:30297208 | 外部中断要使能AFIO,我也遇到这个问题 | ||
![]() |
![]() ![]() ![]() ![]() | ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
【4楼】 panda1988 积分:28 派别: 等级:------ 来自: | 回复【3楼】foxsports ----------------------------------------------------------------------- 谢谢你的热心回帖!呵呵, 我昨天晚上解决了这个问题,当初在看资料的时候有点粗心,没注意RCC_APB2ENR寄丛器的最后一位AFIOEN,固件库里没有这一位的相关配置!就给忘了,害得我折腾了两天。看来以后要很细心啦! 本贴被 panda1988 编辑过,最后修改时间:2010-05-03,09:20:49. | ||
![]() |
![]() ![]() ![]() ![]() | ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
【5楼】 panda1988 积分:28 派别: 等级:------ 来自: | 我改变了下边代码第一句就好了! RCC->APB2ENR |=0x09;//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//打开用到的gpiob时钟和IO口复用时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;//选择要配置的端口 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//配置为浮空输入 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//转换速度 GPIO_ResetBits(GPIOB, GPIO_Pin_All); //先复位 GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化gpio |
联系客服