rt
现象:用相同的方法配置tiM1、TIM2、TIM4,但TIM1正常,TIM2、TIM4完全不跑,找了很久资料毫无进展,求帮助,看有啥缺漏,谢谢!!!
固件库2.1.0
IAR stm8 1.41.1
使用st-link v2
- void main(void)
- {
- CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
- /*
- 串口初始化代码
- */
- /*TIM1初始化*/
- CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1,ENABLE);
- TIM1_DeInit();
- TIM1_SetCounter(0);
- TIM1_TimeBaseInit(15999,TIM1_COUNTERMODE_UP,100,0);
- /*TIM2初始化*/
- CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2,ENABLE);
- TIM2_DeInit();
- TIM2_SetCounter(0);
- TIM2_TimeBaseInit(TIM2_PRESCALER_16384, 100);
- TIM2_PrescalerConfig(TIM2_PRESCALER_16384,TIM2_PSCRELOADMODE_UPDATE);
- /*TIM4初始化*/
- CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4,ENABLE);
- TIM4_DeInit();
- TIM4_SetCounter(0);
- TIM4_TimeBaseInit(TIM4_PRESCALER_128, 100);
- TIM4_PrescalerConfig(TIM4_PRESCALER_128,TIM4_PSCRELOADMODE_UPDATE);
- /*使能定时器*/
- TIM1_Cmd(ENABLE);
- TIM2_Cmd(ENABLE);
- TIM4_Cmd(ENABLE);
- while(1)
- {
- /*打印当前CNT值*/
- printf("%x,%x,%x
",TIM1_GetCounter(),TIM2_GetCounter(),TIM4_GetCounter());
- }
- }
复制代码
输出结果是把3个TIM的CNT打印出来,但只有TIM1在跑。
谢谢!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>