想用GD32F330开发板的定时器1做个定时的角度反馈,设了个10K频率的定时器中断,每计数10次反馈一次角度,结果发现了加了if语句来判断后,一直触发HardFault_Handler,无法执行if里面打印角度操作;关了if语句,又没问题了,操作正常执行。然后我一步步注释代码,发现在判断语句前,用串口打印一次在进行判断,判断语句也不会触发HardFault_Handler,里面指令也是正常进行。想请教一下大伙儿,这是个什么问题?是我定时器配置错了嘛?这是我的定时器配置:
void timer1_interrupt(void)
{
rcu_periph_clock_enable(RCU_TIMER1);
timer_parameter_struct timer_initpara;
timer_deinit(TIMER1);
timer_initpara.prescaler =35;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 199;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter =0;
timer_init(TIMER1, &timer_initpara);
timer_interrupt_enable(TIMER1,TIMER_INT_UP);
timer_enable(TIMER1);
}
void nvic_config(void)
{
nvic_irq_enable(TIMER1_IRQn,1,1);
}
int i= 0;
uint16_t angle;
void TIMER1_IRQHandler(void)
{
if ( timer_interrupt_flag_get(TIMER1 , TIMER_INT_UP) != RESET )
{
i = i+1;
timer_interrupt_flag_clear(TIMER1 , TIMER_INT_UP);
if(time ==10)
{
angle = ssi_ReadAngle();
printf(" %d \r\n",angle);
i=0;
}
}
}
|