找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3506|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

STM32求助,為啥tim1定時(shí)器的計(jì)數(shù)器CNT一直是0沒有變化?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:703167 發(fā)表于 2020-4-23 19:36 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
這是初始化的代碼,有啥缺漏?
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;
   
}
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表