最近做個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 */ }