|
我这套读取顺序就是 ST HAL 库函数内部的执行逻辑:
以 5Hz 频率读取 RTC持续测试,每隔数小时就会出现一次读数错误;因此我写了一段代码,出错时重新完整读取一遍所有寄存器。能暂时妥协一下 int getrtc (struct tm * mytime) { RTC_TimeTypeDef sTime = {0}; RTC_DateTypeDef sDate = {0}; int rtcret1=0; int rtcret2=0; RTC_Lock(); // Implement RTC errata sheet (SSR needs reading before and after date/time and compared, until same) uint32_t last_subsec; volatile uint32_t errorcnt=0; // for doing a breakpoint do { last_subsec = (uint32_t)(hrtc.Instance->SSR); // Always read both, even if 1st returns an error rtcret1 = HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN); rtcret2 = HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN); errorcnt++; } while (last_subsec != sTime.SubSeconds); RTC_Unlock(); if ( (rtcret1!=0) || (rtcret2!=0)) return 2; // Convert the 32F4 RTC API to the K&R standard C clock structure "tm" // Comments in setrtc above // No error checking - would be meaningless mytime->tm_year = sDate.Year+100; mytime->tm_mon = sDate.Month-1; mytime->tm_mday = sDate.Date; mytime->tm_wday = sDate.WeekDay; // assume the RTC maintained the day of week correctly if (sDate.WeekDay==7) mytime->tm_wday = 0; mytime->tm_hour = sTime.Hours; mytime->tm_min = sTime.Minutes; mytime->tm_sec = sTime.Seconds; // Load subseconds into a global variable, as microseconds // There were problems with this when using the SHIFTR method to advance the RTC... g_SubSeconds = ((RTC_SYNC_PREDIV-sTime.SubSeconds)*1000000L)/(RTC_SYNC_PREDIV+1); // Calculate day of year from the date, because that doesn't come from the RTC. mytime->tm_yday = day_of_year(mytime->tm_mday, mytime->tm_mon, mytime->tm_year); // Return -1 for daylight saving, as per K&R mytime->tm_isdst = -1; return 0; } |
手册中关于RTC 读取有一些说明,包括读取方式,读取时 总线速度。不同速度下的方式也有区别。可以对照一下。
|
STM32F405ZGT6 批次22+ 问下这颗料,60度烘烤12小时后,出现鼓包,是怎么回事? 原厂有标准的烘烤温度范围 跟时长范围吗?
非官方开发板第一次下载成功,之后就各种失败
STM32H5F/E 相比 STM32F4 系列最大的优势是什么?
ST TOF问题请教
STM32F4的SPI端口,如何实现多通道输入?
STM32F4标准库USB例程CDC_HID_Composite问题:第一次识别成功,后续插入电脑均识别失败
STM32F407 Flash 故障
STM32F407使用LAN8720A进行网口通信
USBX在F407上创建CDC不能正常使用
STM32F407 音频输入输出时 IFFT 无法正常工作
微信公众号
手机版