利用RTC生成亚秒级时钟的步骤:

 1.打开STM32CubeMx,使能RTC。

利用RTC生成亚秒级时钟

2.配置分频器数值、初始时间,日期

利用RTC生成亚秒级时钟

3.生成代码。

4.在主函数中调用代码并输出。

        RTC_TimeTypeDef stimestructure;
        RTC_DateTypeDef sdatestructure; HAL_RTC_GetTime(&hrtc, &stimestructure, RTC_FORMAT_BIN);
        HAL_RTC_GetDate(&hrtc, &sdatestructure, RTC_FORMAT_BIN);
        
        fsecond=(float)stimestructure.Seconds+(float)(15999-stimestructure.SubSeconds)/16000;
        printf("%02d/%02d/%02d\r\n",2000 + sdatestructure.Year, sdatestructure.Month, sdatestructure.Date);
        printf("%02d:%02d:%f\r\n",stimestructure.Hours, stimestructure.Minutes,fsecond);

 

相关文章: