21ic问答首页 - GD32定时器触发HardFault_Handler
GD32定时器触发HardFault_Handler
恩成2022-11-15
想用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;
}
}
}
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;
}
}
}
赞0
评论
2022-11-21
赞0
评论
2022-11-21
赞0
评论
2022-11-19
赞0
评论
2022-11-19
赞0
没有用中断,就是初始化之后重定向了一下
评论
2022-11-17
赞0
串口打印没有用中断,就是简单的初始化,重定向了一下
评论
2022-11-17
赞0
评论
2022-11-17
赞0
评论
2022-11-17
赞0
改成1ms一次,发现效果更差了,之前在if语句前加个打印函数,if里面的还能照常执行。现在直接卡在中断里面,然后跳到hardfualt里面了
评论
2022-11-16
您需要登录后才可以回复 登录 | 注册