【GD32L233C-START评测】2,定时器中断
[复制链接]
由于某种原因,要用到定时器中断,看看例程可以说没有,于是我就自己上阵了。
我查了库函数手册,加了定时器1中断允许,也在gd32l23x_it.c中加入了如下函数:
void TIMER1_IRQHandler(void)
{
timer_flag_clear(TIMER1, TIMER_FLAG_UP);
gd_eval_led_toggle(LED1);
}
但是编译后不好用,打断点就是不进入。
我在网上找了半天也无果,我就试着加入了总中断允许。就是nvic_irq_enable部分,这下好了。
timer_interrupt_enable(TIMER1,TIMER_INT_UP);
nvic_irq_enable(TIMER1_IRQn ,1);
全部代码是我从例程修的:
void timer_config(void)
{
/* -----------------------------------------------------------------------
TIMER2CLK is 100KHz
TIMER2 channel duty cycle = (25000/ 50000)* 100 = 50%
----------------------------------------------------------------------- */
timer_oc_parameter_struct timer_ocintpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER1);
timer_deinit(TIMER1);
/* TIMER configuration */
timer_struct_para_init(&timer_initpara);
timer_initpara.prescaler = 639;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 49999;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_init(TIMER1, &timer_initpara);
/* configurate channel */
// timer_channel_output_struct_para_init(&timer_ocintpara);
// timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH;
// timer_ocintpara.outputstate = TIMER_CCX_ENABLE;
// timer_channel_output_config(TIMER2, TIMER_CH_0, &timer_ocintpara);
// /* configure TIMER channel output pulse value */
// timer_channel_output_pulse_value_config(TIMER2, TIMER_CH_0, 25000);
// /* configurate channel in PWM mode0 */
// timer_channel_output_mode_config(TIMER2, TIMER_CH_0, TIMER_OC_MODE_PWM0);
// timer_channel_output_shadow_config(TIMER2, TIMER_CH_0, TIMER_OC_SHADOW_DISABLE);
timer_interrupt_enable(TIMER1,TIMER_INT_UP);
nvic_irq_enable(TIMER1_IRQn ,1);
timer_counter_value_config(TIMER1,0);
timer_interrupt_flag_clear(TIMER1, TIMER_INT_FLAG_UP);
/* auto-reload preload enable */
timer_auto_reload_shadow_enable(TIMER1);
/* auto-reload preload enable */
timer_enable(TIMER1);
}
至于定时的时间,还有待进一步研究。
|