你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 6856|回复: 9

【求助】按键外部中断进不去,用的3.4的库

[复制链接]

3

主题

13

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2011-4-19 09:34:37 | 显示全部楼层 |阅读模式
<div class="t_msgfontfix">[table]            [tr]            [td]本人刚接触STM32,希望大侠们指教,谢谢!
            
            按键外部中断进不去,用的3.4的固件库,按键为下降沿中断方式,接在mcu的PC13口,程序实现功能为LED起初循环点亮,按键按下时,执行中断程序,其中LED由PF口控制,如下
            /*******************************************************************************
            * File Name          : main.c
            * Author             : Nanjing
            * Date First Issued  : 04/12/2011
            * Description        : Main program body
            ********************************************************************************/
            /* Includes ------------------------------------------------------------------*/
            #include "stm32f10x.h"
            #include "main.h"
            /* Private typedef -----------------------------------------------------------*/
            /* Private define ------------------------------------------------------------*/
            /* Private macro -------------------------------------------------------------*/
            /* Private variables ---------------------------------------------------------*/
            static __IO uint32_t TimingDelay;
            NVIC_InitTypeDef NVIC_InitStructure;
            GPIO_InitTypeDef GPIO_InitStructure;
            EXTI_InitTypeDef EXTI_InitStructure;
            ErrorStatus HSEStartUpStatus;
            /* Private function prototypes -----------------------------------------------*/
            void Delay(__IO uint32_t nTime);
            void RCC_Configuration(void) ;
            void SysTick_Configuration(void);
            void GPIO_Configuration(void);
            void EXTI_Configuration(void);
            /* Private functions ---------------------------------------------------------*/
            /*******************************************************************************
            * Function Name  : main
            * Description    : Main program.
            * Input          : None
            * Output         : None
            * Return         : None
            *******************************************************************************/
            int main(void)
            {
            #ifdef DEBUG
            debug() ;
            #endif
              /* Setup SysTick Timer for 1 msec interrupts  */
            
              /* Configure the system clocks */
            RCC_Configuration();
            SysTick_Configuration();
            
            /* Configure the GPIO ports */
            GPIO_Configuration();
            EXTI_Configuration();
            
            /***循环点亮LED****/
              for(;;)
            {
            GPIOF->ODR=0xfffffc4f;
              /* Insert 50 ms delay */
                Delay(500);
            GPIOF->ODR=0xfffffc8f;
            /* Insert 50 ms delay */
                Delay(500);
            GPIOF->ODR=0xfffffd0f;
            /* Insert 50 ms delay */
                Delay(500);
            GPIOF->ODR=0xfffffe0f;
            /* Insert 50 ms delay */
                Delay(500);
            }
            }
            /**
              * @brief  Inserts a delay time.
              * @param  nTime: specifies the delay time length, in milliseconds.
              * @retval None
              */
            void SysTick_Configuration(void)
            {
                /* Setup SysTick Timer for 100 msec interrupts */
                if (SysTick_Config((SystemCoreClock) / 1000))     //     1/1000s=1ms
            {
                    /* Capture error */
                    while (1);
            }
                NVIC_SetPriority(SysTick_IRQn, 0x0);
            }
            void Delay(__IO uint32_t nTime)   //定义nTime为可读可写的int
            {
              TimingDelay = nTime;
              while(TimingDelay != 0);
            }
            /**
              * @brief  Decrements the TimingDelay variable.
              * @param  None
              * @retval None
              */
            void TimingDelay_Decrement(void)
            {
              if (TimingDelay != 0x00)
              {
                TimingDelay--;
              }
            }
            /*******************************************************************************
            * Function Name  : GPIO_Configuration
            * Description    : Configures the different GPIO ports.
            * Input          : None
            * Output         : None
            * Return         : None
            *******************************************************************************/
            void NVIC_Configuration(void)
            {
            #ifdef VECT_TAB_RAM
            NVIC_SetVectorTable(NVIC_VectTab_RAM,0x0);
            #else
            NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
            #endif
              NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
              NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn;
              NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
              NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
              NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
              NVIC_Init(&NVIC_InitStructure);
            }
            
            void RCC_Configuration(void)
            {
               //必须开时钟才能 使用起来 相应IO
               RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF|RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO,ENABLE);
            }
            /*******************************************************************************
            * Function Name  : GPIO_Configuration
            * Description    : Configures the different GPIO ports.
            * Input          : None
            * Output         : None
            * Return         : None
            
            *******************************************************************************/
            void GPIO_Configuration(void)
            {
              /*配置PF口为输出推免,速度50MHz*/
            GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9;
            GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
            GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
            GPIO_Init(GPIOF,&GPIO_InitStructure);
              /* Configure PC13 as input floating (EXTI Line13) */
            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
            GPIO_Init(GPIOC, &GPIO_InitStructure);
            }
            
            void EXTI_Configuration(void)
            {
              /* Configure EXTI Line13 to generate an interrupt on falling edge */  
                GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13);   //选择中断管脚PC13
            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);
            }
            /*******************************************************************************
            * Function Name  : Delay
            * Description    : Inserts a delay time.
            * Input          : nCount: specifies the delay time length.
            * Output         : None
            * Return         : None
            *******************************************************************************/
              #ifdef DEBUG
              /*描述:当程序出错时,返回出错的文件名及在源程序中的行号
               输入:—file:指向文件名的指针
               —line:在源程序中的行号
               输出:无
               返回:无
               */
               void assert_failed(u8*file,u32 line)
               {
               while(1) {}
               }
            #endif
            
            
            以下为用到的中断程序:
            void SysTick_Handler(void)
            {
            TimingDelay_Decrement();
            }
            
            void EXTI15_10_IRQHandler(void)
            {  int i;
            if(EXTI_GetITStatus(EXTI_Line13)!=RESET)
            {
            //二极管全部熄灭
            for(i=0;iODR=0xfffffc3f;
            //  /* Insert 50 ms delay */
            //    Delay(500);
            //二极管全部点亮
            for(i=0;iODR=0xffffffff;
            // /* Insert 50 ms delay */
            //    Delay(500);
            for(i=0;i
回复

使用道具 举报

3

主题

13

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
 楼主| 发表于 2011-4-19 09:36:32 | 显示全部楼层

RE:【求助】按键外部中断进不去,用的3.4的库

现在的情况是编译无错,LED循环点亮,但是按键无反应,进不了中断,请大家指教,谢谢!!!
回复 支持 反对

使用道具 举报

7

主题

62

回帖

0

蝴蝶豆

新手上路

最后登录
2020-6-1
发表于 2011-4-19 10:05:12 | 显示全部楼层

RE:【求助】按键外部中断进不去,用的3.4的库

还是不要用SysTick_Handler做定时比较好,用TIMx定时似乎不会有这个问题。
回复 支持 反对

使用道具 举报

134

主题

4489

回帖

239

蝴蝶豆

版主

最后登录
2020-12-9
发表于 2011-4-19 10:07:36 | 显示全部楼层

RE:【求助】按键外部中断进不去,用的3.4的库

NVIC_Configuration()没有初始化。你加入main.c中。
回复 支持 反对

使用道具 举报

16

主题

121

回帖

0

蝴蝶豆

初级会员

最后登录
2020-8-5
发表于 2011-4-19 10:16:53 | 显示全部楼层

RE:【求助】按键外部中断进不去,用的3.4的库

1.你是没有NVIC_Configuration()没有初始化.(斑主说过了)
2.需要加入EXTI_GenerateSWInterrupt(EXTI_Line13);//设置PC13口为外部中断输入线13产生一个软件中断
回复 支持 反对

使用道具 举报

3

主题

13

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
 楼主| 发表于 2011-4-19 11:42:14 | 显示全部楼层

回复:【求助】按键外部中断进不去,用的3.4的库

谢谢以上回答,我试试
回复 支持 反对

使用道具 举报

3

主题

13

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
 楼主| 发表于 2011-4-19 11:59:32 | 显示全部楼层

RE:【求助】按键外部中断进不去,用的3.4的库

还是不行,进不了中断
回复 支持 反对

使用道具 举报

3

主题

13

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
 楼主| 发表于 2011-4-19 12:04:34 | 显示全部楼层

RE:【求助】按键外部中断进不去,用的3.4的库

行了,谢谢楼上几位
回复 支持 反对

使用道具 举报

0

主题

1

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2012-8-10 20:42:49 | 显示全部楼层

回复:【求助】按键外部中断进不去,用的3.4的库

回复第 8 楼 于2011-04-19 12:04:34发表:
行了,谢谢楼上几位 

请问你是怎么解决的啊,我也出现了这个问题
回复 支持 反对

使用道具 举报

0

主题

2

回帖

0

蝴蝶豆

新手上路

最后登录
1970-1-1
发表于 2013-7-2 18:52:28 | 显示全部楼层

回复:【求助】按键外部中断进不去,用的3.4的库

EXTI15_10_IRQn重新定义下,在conf.h中#define   XXXXXX                        EXTI15_10_IRQn
基于固件库的工程调用不了stm32f10x.h里面的定义,不知为何。。。
回复 支持 反对

使用道具 举报

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版