STM32F4xx HAL Documentation
Hardware Abstraction Layer for STM32F4 familiy
Loading...
Searching...
No Matches
RTC Time and Date functions

RTC Time and Date functions. More...

Collaboration diagram for RTC Time and Date functions:

Functions

HAL_StatusTypeDef HAL_RTC_SetTime (RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
 Sets RTC current time.
 
HAL_StatusTypeDef HAL_RTC_GetTime (RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
 Gets RTC current time.
 
HAL_StatusTypeDef HAL_RTC_SetDate (RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
 Sets RTC current date.
 
HAL_StatusTypeDef HAL_RTC_GetDate (RTC_HandleTypeDef *hrtc, RTC_DateTypeDef *sDate, uint32_t Format)
 Gets RTC current date.
 

Detailed Description

RTC Time and Date functions.

 ===============================================================================
                 ##### RTC Time and Date functions #####
 ===============================================================================

 [..] This section provides functions allowing to configure Time and Date features

Function Documentation

◆ HAL_RTC_SetTime()

HAL_StatusTypeDef HAL_RTC_SetTime ( RTC_HandleTypeDef * hrtc,
RTC_TimeTypeDef * sTime,
uint32_t Format )

#include <stm32f4xx_hal_rtc.h>

Sets RTC current time.

Parameters
hrtcpointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC.
sTimePointer to Time structure
Note
DayLightSaving and StoreOperation interfaces are deprecated. To manage Daylight Saving Time, please use HAL_RTC_DST_xxx functions.
Parameters
FormatSpecifies the format of the entered parameters. This parameter can be one of the following values:
  • RTC_FORMAT_BIN: Binary data format
  • RTC_FORMAT_BCD: BCD data format
Return values
HALstatus

Definition at line 698 of file stm32f4xx_hal_rtc.c.

References __HAL_LOCK, __HAL_RTC_WRITEPROTECTION_DISABLE, __HAL_RTC_WRITEPROTECTION_ENABLE, __HAL_UNLOCK, assert_param, RTC_TimeTypeDef::DayLightSaving, HAL_OK, HAL_RTC_STATE_BUSY, HAL_RTC_STATE_READY, RTC_TimeTypeDef::Hours, RTC_HandleTypeDef::Instance, IS_RTC_DAYLIGHT_SAVING, IS_RTC_FORMAT, IS_RTC_HOUR12, IS_RTC_HOUR24, IS_RTC_HOURFORMAT12, IS_RTC_MINUTES, IS_RTC_SECONDS, IS_RTC_STORE_OPERATION, RTC_TimeTypeDef::Minutes, RTC_Bcd2ToByte(), RTC_ByteToBcd2(), RTC_EnterInitMode(), RTC_ExitInitMode(), RTC_FORMAT_BIN, RTC_TR_RESERVED_MASK, RTC_TimeTypeDef::Seconds, RTC_HandleTypeDef::State, RTC_TimeTypeDef::StoreOperation, and RTC_TimeTypeDef::TimeFormat.

◆ HAL_RTC_GetTime()

HAL_StatusTypeDef HAL_RTC_GetTime ( RTC_HandleTypeDef * hrtc,
RTC_TimeTypeDef * sTime,
uint32_t Format )

#include <stm32f4xx_hal_rtc.h>

Gets RTC current time.

Parameters
hrtcpointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC.
sTimePointer to Time structure
FormatSpecifies the format of the entered parameters. This parameter can be one of the following values:
  • RTC_FORMAT_BIN: Binary data format
  • RTC_FORMAT_BCD: BCD data format
Note
You can use SubSeconds and SecondFraction (sTime structure fields returned) to convert SubSeconds value in second fraction ratio with time unit following generic formula: Second fraction ratio * time_unit = [(SecondFraction - SubSeconds) / (SecondFraction + 1)] * time_unit This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS
You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values in the higher-order calendar shadow registers to ensure consistency between the time and date values. Reading RTC current time locks the values in calendar shadow registers until current date is read to ensure consistency between the time and date values.
Return values
HALstatus

Definition at line 812 of file stm32f4xx_hal_rtc.c.

References assert_param, HAL_OK, RTC_TimeTypeDef::Hours, RTC_HandleTypeDef::Instance, IS_RTC_FORMAT, RTC_TimeTypeDef::Minutes, RTC_Bcd2ToByte(), RTC_FORMAT_BIN, RTC_TR_RESERVED_MASK, RTC_TimeTypeDef::SecondFraction, RTC_TimeTypeDef::Seconds, RTC_TimeTypeDef::SubSeconds, and RTC_TimeTypeDef::TimeFormat.

◆ HAL_RTC_SetDate()

HAL_StatusTypeDef HAL_RTC_SetDate ( RTC_HandleTypeDef * hrtc,
RTC_DateTypeDef * sDate,
uint32_t Format )

#include <stm32f4xx_hal_rtc.h>

Sets RTC current date.

Parameters
hrtcpointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC.
sDatePointer to date structure
Formatspecifies the format of the entered parameters. This parameter can be one of the following values:
  • RTC_FORMAT_BIN: Binary data format
  • RTC_FORMAT_BCD: BCD data format
Return values
HALstatus

Definition at line 857 of file stm32f4xx_hal_rtc.c.

References __HAL_LOCK, __HAL_RTC_WRITEPROTECTION_DISABLE, __HAL_RTC_WRITEPROTECTION_ENABLE, __HAL_UNLOCK, assert_param, RTC_DateTypeDef::Date, HAL_OK, HAL_RTC_STATE_BUSY, HAL_RTC_STATE_READY, RTC_HandleTypeDef::Instance, IS_RTC_DATE, IS_RTC_FORMAT, IS_RTC_MONTH, IS_RTC_WEEKDAY, IS_RTC_YEAR, RTC_DateTypeDef::Month, RTC_Bcd2ToByte(), RTC_ByteToBcd2(), RTC_DR_RESERVED_MASK, RTC_EnterInitMode(), RTC_ExitInitMode(), RTC_FORMAT_BIN, RTC_HandleTypeDef::State, RTC_DateTypeDef::WeekDay, and RTC_DateTypeDef::Year.

◆ HAL_RTC_GetDate()

HAL_StatusTypeDef HAL_RTC_GetDate ( RTC_HandleTypeDef * hrtc,
RTC_DateTypeDef * sDate,
uint32_t Format )

#include <stm32f4xx_hal_rtc.h>

Gets RTC current date.

Parameters
hrtcpointer to a RTC_HandleTypeDef structure that contains the configuration information for RTC.
sDatePointer to Date structure
FormatSpecifies the format of the entered parameters. This parameter can be one of the following values:
  • RTC_FORMAT_BIN: Binary data format
  • RTC_FORMAT_BCD: BCD data format
Note
You must call HAL_RTC_GetDate() after HAL_RTC_GetTime() to unlock the values in the higher-order calendar shadow registers to ensure consistency between the time and date values. Reading RTC current time locks the values in calendar shadow registers until current date is read to ensure consistency between the time and date values.
Return values
HALstatus

Definition at line 946 of file stm32f4xx_hal_rtc.c.

References assert_param, RTC_DateTypeDef::Date, HAL_OK, RTC_HandleTypeDef::Instance, IS_RTC_FORMAT, RTC_DateTypeDef::Month, RTC_Bcd2ToByte(), RTC_DR_RESERVED_MASK, RTC_FORMAT_BIN, RTC_DateTypeDef::WeekDay, and RTC_DateTypeDef::Year.