微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 嵌入式设计讨论 > MCU和单片机设计讨论 > STM32无法进入外部中断

STM32无法进入外部中断

时间:10-02 整理:3721RD 点击:
各位大侠好  小弟今年刚毕业学习STM32  现在编程外部中断时无法进入中断函数  恳请大侠们帮小弟看看  小弟感激不尽!  

PC6控制LED灯,高电平亮,低电平灭;  PD13连接按键,外部中断,接有上拉,通过10K电阻接入3.3V, 程序无法进入中断,将PD13改为PD4,程序可以正常中断。
  程序如下:
    正常灯亮,按键后灯灭,但按键后灯还亮着     编程软件  MDK5.10    STM32F103VBT6   程序编译无错误
#include "stm32f10x_lib.h"
EXTI_InitTypeDef EXTI_InitStructure;
ErrorStatus HSEStartUpStatus;
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void delay(u32 n);
int main(void)
{
#ifdef DEBUG
  debug();
#endif
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource13);
   EXTI_InitStructure.EXTI_Line = EXTI_Line13;
   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
   EXTI_Init(&EXTI_InitStructure);
   delay(0xffff);
  GPIO_SetBits(GPIOC, GPIO_Pin_6);
         delay(0xffff);
   EXTI_GenerateSWInterrupt(EXTI_Line13);
   while (1)
  {
  }
}

void RCC_Configuration(void)
{
  RCC_DeInit();
  RCC_HSEConfig(RCC_HSE_ON);
  HSEStartUpStatus = RCC_WaitForHSEStartUp();
        if(HSEStartUpStatus == SUCCESS)
  {
   FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
   FLASH_SetLatency(FLASH_Latency_2);
   RCC_HCLKConfig(RCC_SYSCLK_Div1);
   RCC_PCLK2Config(RCC_HCLK_Div1);
                RCC_PCLK1Config(RCC_HCLK_Div2);
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
    RCC_PLLCmd(ENABLE);
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }
   RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
   while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOC
                         | RCC_APB2Periph_AFIO, ENABLE);
}

void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
}

void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
#ifdef  VECT_TAB_RAM  
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);   
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}
#ifdef  DEBUG
void assert_failed(u8* file, u32 line)
{
  while (1)
  {
  }
}
#endif

中断程序
void EXTI15_10_IRQHandler(void)
{  delay(0xffff);
       
        if(EXTI_GetITStatus(EXTI_Line13) != RESET)
  {
    GPIO_ResetBits(GPIOC, GPIO_Pin_6);
    EXTI_ClearITPendingBit(EXTI_Line13);
  }
}


在线等!

各位大侠,问题已经解决,是固件库版本过低(V1.0)造成的,无法EXIT9_5中断,将固件库升级为V2.0后,EXIT9_5可以中断,谢谢大家关注!

具体可百度颖展ic芯片进官网查询

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top