在线时间1 小时
UID351372
ST金币0
蝴蝶豆0
注册时间2012-4-5
新手上路
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2012-5-17 11:59:10
|
显示全部楼层
a0a.1 0b0c
回复:STM32F103ZET6 外部中断问题
回复第 6 楼 于2012-05-17 09:35:49发表:
HardFault_Handler,这个说明你的程序有错误,导致进入这个错误中断。检查一下,是不是有野指针的操作?
我用的是IAR编译器
按键是PA8,LED1接PF8,LED2接PF9,正常的程序是LED1和LED2交替闪烁,无限循环;LED3接PF6,LED4接PF7,进入中断服务程序时LED3,LED4交替闪烁10次
可当我下载完程序时,直接运行,按键按下时,没有反应,然后Break了下,发现指针停在了HardFault_handler上面了~~
我的程序如下:
main.c
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_exti.h"
#include "stm32_eval.h"
#include
/* Private function prototypes -----------------------------------------------*/
//void RCC_Configuration(void); //时钟配置
void NVIC_Configuration(void);//中断向量表和优先级设定
void GPIO_Configuartion(void);//端口模式配置
void Exti_Configuartion(void);//外部中断模式配置
/* Private functions ---------------------------------------------------------*/
static void Delay_ARMJISHU(__IO uint32_t nCount)
{
for (; nCount != 0; nCount--);
}
/*******************************************************************************
* Function Name : main
* Description : Main program.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
int main(void)
{
// RCC_Configuration(); //配置时钟
NVIC_Configuration();
GPIO_Configuartion();
Exti_Configuartion();
while (1)
{
Delay_ARMJISHU(0xffff);
GPIO_ResetBits(GPIOF, GPIO_Pin_8 );//点亮led
GPIO_SetBits(GPIOF, GPIO_Pin_9);//熄灭led
Delay_ARMJISHU(0xffff);//Dealy_Systick(1000);
GPIO_ResetBits(GPIOF, GPIO_Pin_9 );//点亮led
GPIO_SetBits(GPIOF, GPIO_Pin_8);//熄灭led
}
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
//中断向量存储在FlASh区
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//选择中断优先级分组1
NVIC_InitStructure.NVIC_IRQChannel=EXTI9_5_IRQn;//外部中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void GPIO_Configuartion(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//LED控制端口
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);//打开用到的gpiod时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7|GPIO_Pin_8 | GPIO_Pin_9;//选择要配置的端口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//配置为推免输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//转换速度
GPIO_Init(GPIOF, &GPIO_InitStructure);//初始化gpio
GPIO_ResetBits(GPIOF, GPIO_Pin_8 | GPIO_Pin_9); //先复位
//中断控制端口
//RCC->APB2ENR |=0x09;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//打开用到的gpioa时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;//选择要配置的端口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//配置为上拉输入
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//转换速度
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化gpio
}
/*******************************************************************************
* Function Name : Exti_Configuration
* Description : 配置外部事件,
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void Exti_Configuartion(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource8);
//将PB6配置为EXTI Line6
EXTI_InitStructure.EXTI_Line=EXTI_Line8;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStructure);
//EXTI_GenerateSWInterrupt(EXTI_Line8);
}
中断程序啊:stm32f10x_it.c
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
static void Delay_ARMJISHU(__IO uint32_t nCount)
{
for (; nCount != 0; nCount--);
}
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_it.h"
void EXTI9_5_IRQHandler(void)
{
int i;
if(EXTI_GetITStatus(EXTI_Line8)!=RESET)
{
for(i=0;i |
|