stm32 RTC如何獲取ms計時


  最近做個CAN記錄器,想保存時間但是RTC只記錄到秒,不能保存ms。百度沒看到解決方法。自己搗鼓了一下。

  RTC有個亞秒寄存器,通過計算可以得到ms級計時。

    RTC_TimeTypeDef stimestructure;
    RTC_DateTypeDef sdatestructure; 

    while (1)
    {
        /* USER CODE END WHILE */
        HAL_RTC_GetTime(&hrtc, &stimestructure, RTC_FORMAT_BIN);
        HAL_RTC_GetDate(&hrtc, &sdatestructure, RTC_FORMAT_BIN);
        
        // 亞秒值
        printf("%.3f,%d \r\n",(255.0-stimestructure.SubSeconds)/256, HAL_GetTick());
        
//        printf("%02d/%02d/%02d ",2000 + sdatestructure.Year, sdatestructure.Month, sdatestructure.Date);
//        printf("%02d:%02d:%.3f \r\n",stimestructure.Hours, stimestructure.Minutes,stimestructure.Seconds+(255.0-stimestructure.SubSeconds)/256);
        HAL_Delay(10);
        /* USER CODE BEGIN 3 */

    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM