搜索
bottom↓
回复: 1

stm32f207 中断程序求助

[复制链接]

出0入0汤圆

发表于 2012-8-3 12:49:10 | 显示全部楼层 |阅读模式
小弟新手,写了个中断的程序,本意是软件触发一个EXTI_Line0中断,然后在处理EXTI_Line0中断时产生更高级的EXTI_Line1中断嵌套。
但是现在无论如何,EXTI_GenerateSWInterrupt(EXTI_Line0)产生的中断无法顺利跳转到void EXTI0_IRQHandler(void)。


请各路高手不吝指教,电路图和程序我已经上传到附件。

/******************************************************************************/
#include "stm32f2xx.h"
#include "stm32f2xx_exti.h"
#include "misc.h"
#include "stm32f2xx_syscfg.h"
#include "stm32f2xx_it.h"

typedef unsigned char u8;

/*定义PA.0 PC.1 PC.2分别为按键WAKE UP 摇杆JOYC JOYB*/
#define WAKEUP_KEY_Port                                        GPIOA
#define WAKEUP_KEY_Pin                                        GPIO_Pin_0
#define WAKEUP_KEY_RCC_AHBPeriph                RCC_AHB1Periph_GPIOA

#define JOY_B_KEY_Port                                        GPIOC
#define JOY_B_KEY_Pin                                        GPIO_Pin_2
#define JOY_B_KEY_RCC_AHBPeriph                        RCC_AHB1Periph_GPIOC

#define JOY_C_KEY_Port                                        GPIOC
#define JOY_C_KEY_Pin                                        GPIO_Pin_1
#define JOY_C_KEY_RCC_AHBPeriph                        RCC_AHB1Periph_GPIOC
/******************************************************************************/

/*定义四个LED灯*/
#define LED1_Port                                                GPIOF
#define LED1_Pin                                                GPIO_Pin_6
#define LED1_RCC_AHBPeriph                                RCC_AHB1Periph_GPIOF

#define LED2_Port                                                GPIOF
#define LED2_Pin                                                GPIO_Pin_7
#define LED2_RCC_AHBPeriph                                RCC_AHB1Periph_GPIOF

#define LED3_Port                                                GPIOF
#define LED3_Pin                                                GPIO_Pin_8
#define LED3_RCC_AHBPeriph                                RCC_AHB1Periph_GPIOF

#define LED4_Port                                                GPIOF
#define LED4_Pin                                                GPIO_Pin_9
#define LED4_RCC_AHBPeriph                                RCC_AHB1Periph_GPIOF
/******************************************************************************/


void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void EXTI_Configuration(void);
void Delay(__IO uint32_t nCount);
void Led_Toggle(uint8_t keyvulua);
uint8_t Read_JOYState(void);
/******************************************************************************/


/*主函数*/
int main(void)
{
        RCC_Configuration();
        NVIC_Configuration();
        GPIO_Configuration();
        EXTI_Configuration();
        EXTI_GenerateSWInterrupt(EXTI_Line0);       
        while (1)
        {
          Led_Toggle(Read_JOYState()) ;
        }
}
/******************************************************************************/


/*打开LED 按键 SYSCFG时钟*/
void RCC_Configuration(void)
{
  RCC_AHB1PeriphClockCmd(LED1_RCC_AHBPeriph | LED2_RCC_AHBPeriph | LED3_RCC_AHBPeriph |
  LED4_RCC_AHBPeriph, ENABLE);
  RCC_AHB1PeriphClockCmd(WAKEUP_KEY_RCC_AHBPeriph | JOY_B_KEY_RCC_AHBPeriph |  
  JOY_C_KEY_RCC_AHBPeriph, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
}
/******************************************************************************/


void GPIO_Configuration(void)
{

        GPIO_InitTypeDef GPIO_InitStructure;
       
        /* Configure PF6 PF7 PF8 PF9 in output pushpull mode */
        GPIO_InitStructure.GPIO_Pin = LED1_Pin;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
        GPIO_Init(LED1_Port, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = LED2_Pin;
        GPIO_Init(LED2_Port, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = LED3_Pin;
        GPIO_Init(LED3_Port, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = LED4_Pin;
        GPIO_Init(LED4_Port, &GPIO_InitStructure);
/******************************************************************************/
       
        /* Key GPIO Config */
        GPIO_InitStructure.GPIO_Pin = WAKEUP_KEY_Pin;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
        GPIO_Init(WAKEUP_KEY_Port, &GPIO_InitStructure);

        GPIO_InitStructure.GPIO_Pin = JOY_B_KEY_Pin;
        GPIO_Init(JOY_B_KEY_Port, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = JOY_C_KEY_Pin;
        GPIO_Init(JOY_C_KEY_Port, &GPIO_InitStructure);
/******************************************************************************/
           
        /*配置外部中断输入通道*/
        SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA,EXTI_PinSource0);
        SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC,EXTI_PinSource1);
        SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC,EXTI_PinSource2);       
}
/******************************************************************************/


uint8_t Read_JOYState(void)
{
        if(!GPIO_ReadInputDataBit(WAKEUP_KEY_Port,WAKEUP_KEY_Pin))       
                        return 0;               
        else if(!GPIO_ReadInputDataBit(JOY_B_KEY_Port,JOY_B_KEY_Pin))
                        return 1;               
        else if(!GPIO_ReadInputDataBit(JOY_C_KEY_Port,JOY_C_KEY_Pin))       
                       return 2;
                return 3;
}  

void Led_Toggle(uint8_t keyvulua)
{
        switch(keyvulua)
                {       
                        case 0:
                                GPIO_SetBits(LED1_Port , LED1_Pin);
                                GPIO_SetBits(LED2_Port , LED2_Pin);
                    Delay(0xffffff);
                                break;       
                        case 1:
                                GPIO_SetBits(LED3_Port , LED3_Pin);
                                GPIO_SetBits(LED4_Port , LED4_Pin);
                        Delay(0xffffff);
                                break;
                        case 2:
                                  GPIO_ResetBits(LED1_Port , LED1_Pin);
                                GPIO_ResetBits(LED2_Port , LED2_Pin);
                                GPIO_ResetBits(LED3_Port , LED3_Pin);
                                GPIO_ResetBits(LED4_Port , LED4_Pin);
                    Delay(0xffffff);
                                break;
                        case 3:
                            break;
                }
}
/******************************************************************************/


static void Delay(__IO uint32_t nCount)
{
  while(nCount--)
  {
  }
}
/******************************************************************************/



void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/*根据预编译条件决定中断向量表起始地址*/
#ifdef NVIC_VectTab_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM,0x0);
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
#endif
/******************************************************************************/

/*选择NVIC优先级分组2,使能EXTI0 EXTI1 EXTI2通道*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannel=EXTI1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);

NVIC_InitStructure.NVIC_IRQChannel=EXTI2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/******************************************************************************/


void EXTI_Configuration(void)
{
        EXTI_InitTypeDef EXTI_InitStructure;
                                     
        EXTI_InitStructure.EXTI_Line=EXTI_Line0|EXTI_Line1|EXTI_Line2;
        EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
        EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;
        EXTI_InitStructure.EXTI_LineCmd=ENABLE;
        EXTI_Init(&EXTI_InitStructure);
}
/******************************************************************************/

void EXTI0_IRQHandler(void)
{
             if(EXTI_GetITStatus(EXTI_Line0) != RESET)
  {
   
        Led_Toggle(0);               
            EXTI_GenerateSWInterrupt(EXTI_Line1);
                Led_Toggle(1);
        EXTI_ClearFlag(EXTI_Line0);
  }
               
               
}

void EXTI1_IRQHandler(void)
{
            Led_Toggle(1);               
                EXTI_GenerateSWInterrupt(EXTI_Line2);
                Led_Toggle(0);
                EXTI_ClearFlag(EXTI_Line1);
}       

void EXTI2_IRQHandler(void)
{
            Led_Toggle(2);
                EXTI_ClearFlag(EXTI_Line2);
}               
/******************************************************************************/

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif


/*****************************END OF FILE****************************************/

程序大概是想用软件触发一个EXTI_Line0

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

 楼主| 发表于 2012-8-7 15:58:52 | 显示全部楼层
晕,帖子沉了啊。。。
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-8-25 22:18

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表