OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2956|回复: 0

求助,为啥tim1定时器的计数器CNT一直是0没有变化?

[复制链接]

1

主题

1

帖子

0

精华

新手上路

积分
46
金钱
46
注册时间
2020-4-23
在线时间
22 小时
发表于 2020-4-23 19:34:21 | 显示全部楼层 |阅读模式
1金钱


这是初始化的代码,有啥缺漏啊?
void Tim1Init()
{
    //Reset TIM1 clock
    RCC->APB2RSTR.TIM1RST  = 1;
    //Enable TIM1 clock
    RCC->APB2ENR.TIM1EN    = 1;
   
    // Select the Counter Mode :Center-aligned mode (up/down counting)
    TIM1->CR1.CMS          = 3;
   
    // Set the clock division :No division
    TIM1->CR1.CKD          = 3;
    //Set the auto-reload preload :TIMx_ARR register is buffered
    TIM1->CR1.ARPE         = 1;
   
    //Set the Autoreload value :10000(Arr)
    TIM1->CNT.CNT          = 0;
    TIM1->ARR.ARR          = 10000;
    // Set the Prescaler value :7199 (CK_CNT = CK_PSC /( PSC[15:0]+1))
    TIM1->PSC.PSC          = 7199;
    // Set the Repetition Counter value :0,is no repetition
    TIM1->RCR.REP          = 0;
   
    //Generate an update event to reload the Prescaler and the repetition counter (only for advanced timer) value immediately :UG
    TIM1->EGR.UG           = 1;

    //ClockSourceConfig:internal clock-CK_INT
    //Reset the SMS, TS, ECE, ETPS and ETRF bits:0
    TIM1->SMCR.SMS        = 0;
    TIM1->SMCR.TS         = 0;
    TIM1->SMCR.ECE        = 0;
    TIM1->SMCR.ETPS       = 0;
    TIM1->SMCR.ETF        = 0;
    // Select the TRGO source and Set master mode :0
    TIM1->CR2.MMS         = 0;
    TIM1->SMCR.MSM        = 0;
   
    //Enable trigger:Update interrupt enable
    TIM1->DIER.TIE         = 1;
    TIM1->DIER.UIE         = 1;
   
    //Init TIM1 interrupt  
    //TIM1_UP_IRQn = 25,     /*!< TIM1 Update Interrupt
    //prioritygroup:4  PreemptPriority:1 SubPriority:0
    NVIC->IP[25]           = 0x40;
    //Enable interrupt IRQn  (uint32_t)(1UL << (((uint32_t)25) & 0x1FUL)) :ISER[0]'s 25 bits = 1;
    NVIC->ISER[0]          = 0x02000000;
   
    //Enable Counter
    TIM1->CR1.CEN          = 1;
   
}



正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-5-26 02:47

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表