在配置好的项目中,点开.ioc 文件, 打开cubeMX.
选中RTC, 勾选 Activate Clock Source 和 Activate Calendar
stm32 RTC 应用 cubeMX配置
在这里进行初始值及格式配置
stm32 RTC 应用 cubeMX配置然后generate code。初始化RTC函数便自动生成,接下来便可利用API得到日期和时间的数据

在函数中定义你要存放日期和时间的结构体

RTC_DateTypeDef sdatestructureget;
RTC_TimeTypeDef stimestructureget;

利用 HAL_RTC_GetTime(&hrtc, &stimestructureget, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &sdatestructureget,RTC_FORMAT_BIN);
这两个函数即可得到日期和时间。

详细函数定义及结构定义可在库函数中查看。

相关文章:

  • 2021-08-07
  • 2021-07-07
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-09-22
  • 2021-05-11
猜你喜欢
  • 2022-12-23
  • 2021-04-08
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2021-11-04
  • 2022-12-23
相关资源
相似解决方案