OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 9418|回复: 3

求助!!!关于中断

[复制链接]

4

主题

13

帖子

0

精华

新手上路

积分
49
金钱
49
注册时间
2012-3-24
在线时间
0 小时
发表于 2012-3-27 21:30:03 | 显示全部楼层 |阅读模式

我的主函数

 #include "stm32f10x.h"

void Delay_ms(uint32_t nms)
{
 uint32_t i;
 for(;nms>0;--nms)
  for(i=12000;i>0;--i) ;
}

void RCC_Init(void) //GPIOA, GPIOD时钟,GPIO复用功能时钟初始化
{
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO,ENABLE); 
}

void Led_Init(void)  //LED相关的GPIO初始化
{
 GPIO_InitTypeDef GPIO_InitStruct;
 GPIO_DeInit(GPIOA);
 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8;
 GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;  //推挽输出
 GPIO_Init(GPIOA,&GPIO_InitStruct);   //PA_8引脚

 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
 GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;  //推挽输出
 GPIO_Init(GPIOD,&GPIO_InitStruct);   //PD_2引脚初始化
}

void Key_Init(void)   //按键初始化
{
 GPIO_InitTypeDef GPIO_InitStruct;

 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);  //SWJ和JTAG失能

 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_13 ;
 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU; //13上拉
 GPIO_Init(GPIOA,&GPIO_InitStruct);

 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU; //15上拉
 GPIO_Init(GPIOA,&GPIO_InitStruct);

 GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
 GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD;  //0下拉
 GPIO_Init(GPIOA,&GPIO_InitStruct);
}

void NVIC_Configuration(void)
{
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);  //中断组0

  NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0); //中断向量FLASH   
}

void EXTI_Configuration(void)
{
/***************************WK_UP(PA0)线路中断配置****************************/
 EXTI_InitTypeDef EXTI_InitStruct;   //EXTI初始化结构体
 NVIC_InitTypeDef NVIC_InitStruct; //NVIC初始化结构体

 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);//PA0 
 EXTI_InitStruct.EXTI_Line = EXTI_Line0;    //EXTI外部中断线路0
 EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;  //中断模式
 EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;   //上升沿触发
 EXTI_InitStruct.EXTI_LineCmd = ENABLE;      //中断线路使能
 EXTI_Init(&EXTI_InitStruct);        //初始化EXTI结构体
 
 NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn;   //中断向量线路0
 NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0 
 NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;   //从优先级0
 NVIC_Init(&NVIC_InitStruct);        //初始化NVIC结构体

 /********************KEY1,KEY0(PA13,PA15)中断线路配置***********************/
 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource13);//PA13
 GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource15);//PA15
 EXTI_InitStruct.EXTI_Line = EXTI_Line13 | EXTI_Line15;
 EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
 EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
 EXTI_InitStruct.EXTI_LineCmd = ENABLE;
 EXTI_Init(&EXTI_InitStruct);
 
 NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
 NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;  
 NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
 NVIC_Init(&NVIC_InitStruct);
}

 

int main(void)
{
  
  /* Setup STM32 system (clock, PLL and Flash configuration) */
  SystemInit();
  RCC_Init();
  Led_Init();
  Key_Init();
  NVIC_Configuration();
  EXTI_Configuration();
  while (1)
  {
  }
}

#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

 


下面是我的中断处理函数
void EXTI0_IRQHandler(void)
{
 uint32_t i;
 for(i=0;i<100;++i)
 __nop();
 if(EXTI_GetITStatus(EXTI_Line0) == SET)  //判断中断标志
 {
  EXTI_ClearITPendingBit(EXTI_Line0);  //清楚中断标志
  GPIO_SetBits(GPIOA,GPIO_Pin_8);  //红灯亮
  GPIO_SetBits(GPIOD,GPIO_Pin_2);  //绿灯亮
 }
}

void EXTI15_10_IRQHandler(void)
{
 uint32_t i;
 for(i=0;i<100;++i)
  __nop();
  if(EXTI_GetITStatus(EXTI_Line13) == SET)
 {
  EXTI_ClearITPendingBit(EXTI_Line13); 
  GPIO_ResetBits(GPIOA,GPIO_Pin_8);  //红灯亮
 }
 else if(EXTI_GetITStatus(EXTI_Line15) == SET)
 {
  EXTI_ClearITPendingBit(EXTI_Line15);
  GPIO_ResetBits(GPIOA,GPIO_Pin_8);  //红灯亮
 }

}



搞了一天了。
一直进不了中断,那位哥哥帮忙看看问题出在哪里

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

4

主题

13

帖子

0

精华

新手上路

积分
49
金钱
49
注册时间
2012-3-24
在线时间
0 小时
 楼主| 发表于 2012-3-27 21:31:04 | 显示全部楼层
关于外部中断控制小灯的程序
回复 支持 反对

使用道具 举报

4

主题

13

帖子

0

精华

新手上路

积分
49
金钱
49
注册时间
2012-3-24
在线时间
0 小时
 楼主| 发表于 2012-3-27 22:06:12 | 显示全部楼层
发现了问题了,少了个NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165371
金钱
165371
注册时间
2010-12-1
在线时间
2110 小时
发表于 2012-3-27 22:08:45 | 显示全部楼层
呵呵
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-25 07:32

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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