enterpriseZ 发表于 2012-5-4 16:55:46

为什么stm32的外部中断触发不了?

本帖最后由 enterpriseZ 于 2012-5-4 22:49 编辑

刚刚接触stm32f107不久,今天在学习它的外部中断模块时遇到一点问题,就是设置好中断之后,主程序在死循环里面等待,可是中断程序就是进不去啊!这到底是为什么啊?对着书上看了很久也看不明白啊,求帮助啊!……
PS:程序如下


#include "stm32f10x.h"
void Dis_Init ( void )                                        //显示LED的初始化,接在PD2上的
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOD, ENABLE );
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_Init ( GPIOD, &GPIO_InitStructure );
}
void Interrupt_Init ( void )
{
        EXTI_InitTypeDef EXTI_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
        GPIO_InitTypeDef GPIO_InitStructure;

        RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOC, ENABLE );                                                         //也试过其他的引脚,结果一样
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;                               //浮空输入
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
        GPIO_Init ( GPIOC, &GPIO_InitStructure );

        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 );
       
        NVIC_PriorityGroupConfig ( NVIC_PriorityGroup_1 );                                          //分组方式选择第一组
        NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;                                          //使能EXTI通道
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;                          //先占优先级为0,即抢占优先级为0
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;                                          //从优先级为0,即响应优先级为0
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                                                  //使能
        NVIC_Init ( &NVIC_InitStructure );                                                                          //初始化
}
void delay ( u32 count )
{
        for ( ; count != 0; count -- );
}
int main ( void )                                       
{
        Dis_Init ();
        Interrupt_Init ();
        while (1)
        {
                //死循环
        }
}
void EXTI15_10_IRQHandler ( void )                                //中断处理函数
{
        if ( EXTI_GetITStatus ( EXTI_Line13 ) != RESET )
        {
                EXTI_ClearFlag ( EXTI_Line13 );
                EXTI_ClearITPendingBit ( EXTI_Line13 );
                GPIO_SetBits ( GPIOD, GPIO_Pin_2 );
                delay ( 0xeffffff );
                GPIO_ResetBits ( GPIOD, GPIO_Pin_2 );
                delay ( 0xeffffff );
        }
}

rakcart 发表于 2012-5-4 22:28:50

   GPIO_EXTILineConfig ( GPIO_PortSourceGPIOC, GPIO_PinSource13 );                  //选取PB0口作为中断的输入口
这一行明明是设置GPIOC,怎么是用PB0呢?而且PB的时钟也没有打开。

enterpriseZ 发表于 2012-5-4 22:46:04

rakcart 发表于 2012-5-4 22:28 static/image/common/back.gif
GPIO_EXTILineConfig ( GPIO_PortSourceGPIOC, GPIO_PinSource13 );                  //选取PB0口作为 ...

不好意思啊,后面的注释我可能改过,但是我整个程序中用的都是PC13这个IO口啊!但是在实际应用的过程中有点问题啊!不知道是为什么?

rakcart 发表于 2012-5-5 11:58:38

enterpriseZ 发表于 2012-5-4 22:46 static/image/common/back.gif
不好意思啊,后面的注释我可能改过,但是我整个程序中用的都是PC13这个IO口啊!但是在实际应用的过程中有 ...

PC13链接有外部按键吗?

b260123292 发表于 2012-5-5 12:23:14

开AFIO时钟

enterpriseZ 发表于 2012-5-5 12:28:04

b260123292 发表于 2012-5-5 12:23 static/image/common/back.gif
开AFIO时钟

这个需要怎么设置啊?能顺便说一下嘛?

enterpriseZ 发表于 2012-5-5 12:28:36

rakcart 发表于 2012-5-5 11:58 static/image/common/back.gif
PC13链接有外部按键吗?

有一个独立按键,含上拉电阻

rakcart 发表于 2012-5-5 12:52:46

enterpriseZ 发表于 2012-5-5 12:28 static/image/common/back.gif
这个需要怎么设置啊?能顺便说一下嘛?

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

enterpriseZ 发表于 2012-5-5 13:43:20

rakcart 发表于 2012-5-5 12:52 static/image/common/back.gif
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

好了,表示感谢!!!!{:victory:}

abnerle 发表于 2012-5-5 21:53:05

时钟木有开

enterpriseZ 发表于 2012-5-6 00:07:48

abnerle 发表于 2012-5-5 21:53 static/image/common/back.gif
时钟木有开

那只要GPIO不作为普通的IO使用的话,都要使能相应的时钟么?

abnerle 发表于 2012-5-6 19:34:32

enterpriseZ 发表于 2012-5-6 00:07 static/image/common/back.gif
那只要GPIO不作为普通的IO使用的话,都要使能相应的时钟么?

不管干什么,按理说都要先开的
页: [1]
查看完整版本: 为什么stm32的外部中断触发不了?