STM32 进入不了中断

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STM32 进入不了中断相关的知识,希望对你有一定的参考价值。

void EXTI_Configuartion(void)

EXTI_ClearITPendingBit(EXTI_Line3);

/* Configure Key Button EXTI Line to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Connect Key Button EXTI Line to Key Button GPIO Pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource3); //将PA3连接到外部中断通道4

/* Generate software interrupt: simulate a falling edge applied on Key Button EXTI line */
EXTI_GenerateSWInterrupt(EXTI_Line3);

  /*我不知道你之前的程序,没法判断你错在哪。试试我调试成功的吧,你对照着看看有什么错误。正常情况PB5678循环亮,中断EXTI0_IRQHandler()发生后PB56循环亮,EXTI1_IRQHandler()发生后PB78循环亮,EXTI0的优先级高于EXTI1*/

  #include "stm32f10x.h"
  extern void Delay(vu32 nCount);
  extern void delay(uint);
  void RCC_Config(void);
  void GPIO_Config(void);
  void EXTI_Config(void);
  void NVIC_Config(void);
  int main(void)
  
  //SystemInit();
  RCC_Config();
  GPIO_Config();
  EXTI_Config();
  NVIC_Config();
  while (1)
  
  GPIO_SetBits(GPIOB, GPIO_Pin_5);//GPIOB.5=1
  Delay(0xfffff);
  GPIO_SetBits(GPIOB, GPIO_Pin_6);//GPIOB.6=1
  Delay(0xfffff);
  GPIO_SetBits(GPIOB, GPIO_Pin_7);//GPIOB.7=1
  Delay(0xfffff);
  GPIO_SetBits(GPIOB, GPIO_Pin_8);//GPIOB.8=1
  Delay(0xfffff);
  GPIO_ResetBits(GPIOB, GPIO_Pin_5);//GPIOB.5=0
  Delay(0xfffff);
  GPIO_ResetBits(GPIOB, GPIO_Pin_6);//GPIOB.6=0
  Delay(0xfffff);
  GPIO_ResetBits(GPIOB, GPIO_Pin_7);//GPIOB.7=0
  Delay(0xfffff);
  GPIO_ResetBits(GPIOB, GPIO_Pin_8);//GPIOB.8=0
  Delay(0xfffff);
  
  

  void RCC_Config(void)
  
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
  /*开时钟*/
  
  void GPIO_Config(void)
  
  GPIO_InitTypeDef GPIO_InitStructure;
  GPIO_InitStructure.GPIO_Pin =GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;/*LED为B 5678*/
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_1;//KEY为A 01
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  

  void EXTI_Config(void)
  
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0); //将A0接EXTI0
  EXTI_InitTypeDef EXTI_InitStructure;
  EXTI_InitStructure.EXTI_Line = EXTI_Line0;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//下降沿
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;//中断使能
  EXTI_Init(&EXTI_InitStructure);

  GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource1);//将A1接EXTI1
  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);
  

  void NVIC_Config(void)//中断嵌套优先级设置
  
  NVIC_InitTypeDef NVIC_InitStructure;

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//1组

  /* Enable the EXTI0_IRQn Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;//0
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  /* Enable the EXTI1 Interrupt */
  NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;//1
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  

  extern void Delay(vu32 nCount) //简单的长时间延时函数
  
  int i; //声明内部递减变量
  for(; nCount!= 0; nCount--) //递减变量计数
  
  for (i=0; i<0xffff; i++);
  
  
  /*以下为中断函数,加到stm32f10x_it.c文件中*/
  #include "stm32f10x_it.h"
  void EXTI0_IRQHandler(void)
  
  int i;
  if(EXTI_GetITStatus(EXTI_Line0) != RESET)
  
  /* Clear the Key Button EXTI line pending bit */
  EXTI_ClearITPendingBit(EXTI_Line0);//清中断标志位
  for(i=0;i<2;i++)
  
  GPIO_SetBits(GPIOB, GPIO_Pin_5);//GPIOB.5=1
  Delay(0xfffff);
  GPIO_SetBits(GPIOB, GPIO_Pin_6);//GPIOB.6=1
  Delay(0xfffff);
  GPIO_ResetBits(GPIOB, GPIO_Pin_5);//GPIOB.5=0
  Delay(0xfffff);
  GPIO_ResetBits(GPIOB, GPIO_Pin_6);//GPIOB.6=0
  Delay(0xfffff);
  
  
  
  void EXTI1_IRQHandler(void)
  
  int i;
  if(EXTI_GetITStatus(EXTI_Line1) != RESET)
  
  /* Clear the Key Button EXTI line pending bit */
  EXTI_ClearITPendingBit(EXTI_Line1);//清中断标志位
  for(i=0;i<2;i++)
  
  GPIO_SetBits(GPIOB, GPIO_Pin_7);//GPIOB.7=1
  Delay(0xfffff);
  GPIO_SetBits(GPIOB, GPIO_Pin_8);//GPIOC.8=1
  Delay(0xfffff);
  GPIO_ResetBits(GPIOB, GPIO_Pin_7);//GPIOB.7=0
  Delay(0xfffff);
  GPIO_ResetBits(GPIOB, GPIO_Pin_8);//GPIOB.8=0
  Delay(0xfffff);
  
  
  
参考技术A 同遇到问题,大概是这样的。
问题:串口接收中断跑飞,调试时,串口接一旦收到数据,PC指针就指向0xfffffffe。
背景:工程从别人那拿过来的,板子是VET6
解决:1、system_stm32f10x.c文件里边,128行
#define VECT_TAB_OFFSET 0x20000改成:#define VECT_TAB_OFFSET 0x0
2、魔术棒——target——IROM1由0x8020000改为0x8000000
参考技术B NVIC外部中断位开了吗?

以上是关于STM32 进入不了中断的主要内容,如果未能解决你的问题,请参考以下文章

我想用stm32的DMA方式接收SPI接收到的数据,但是配置完了以后进入不了DMA中断,

stm32外部中断这程序编译没问题,但触发不了外部中断,卡了一天了

STM32 USART接收中断程序问题

stm32外部按键中断无法退出中断问题

STM32外部中断无法进入中断程序,请问下面的程序哪里不对呀???

003:使用SW4STM32不进入中断的原因