我使用STM32F205的TIM3定时器输入捕捉功能用于接收红外信息,程序运行后有时会进入HardFault。在keil中定位到出错位置为TIM3_IRQHandler中断程序,求解导致出错的原因。#define IR_ARRAY_NUM 200
#define High_level 0x80000000
unsigned char first_edge = 0;
unsigned char cap_flag = 0;
unsigned int irTime[IR_ARRAY_NUM] = {0x00};
unsigned short irCount = 0;
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_CC1)!= RESET)
{
if(first_edge == 0)
{
first_edge = 1;
cap_flag = 0x40;
TIM_OC1PolarityConfig(TIM3,TIM_ICPolarity_Rising);
TIM_SetCounter(TIM3,0);
}
else
{
if(cap_flag == 0x40)
{
cap_flag = 0x80;
if(irCount < IR_ARRAY_NUM)
{
irTime[irCount] = TIM_GetCapture1(TIM3);
irCount++;
}
TIM_SetCounter(TIM3,0);
TIM_OC1PolarityConfig(TIM3,TIM_ICPolarity_Falling);
}
else if(cap_flag == 0x80)
{
cap_flag = 0x40;
if(irCount < IR_ARRAY_NUM)
{
irTime[irCount] = TIM_GetCapture1(TIM3)|High_level;
irCount++;
}
TIM_SetCounter(TIM3,0);
TIM_OC1PolarityConfig(TIM3,TIM_ICPolarity_Rising);
}
}
TIM_ClearFlag(TIM3,TIM_IT_CC1);
}
}
|