RTC Time and Date functions.
More...
RTC Time and Date functions.
===============================================================================
##### RTC Time and Date functions #####
===============================================================================
[..] This section provides functions allowing to configure Time and Date features
◆ HAL_RTC_GetDate()
Get RTC current date.
- 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.
- Parameters
-
| hrtc | RTC handle |
| sDate | Pointer to Date structure |
| Format | Specifies 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
-
Definition at line 946 of file stm32l4xx_hal_rtc.c.
954 datetmpreg = (uint32_t)(hrtc->
Instance->DR & RTC_DR_RESERVED_MASK);
957 sDate->
Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> RTC_DR_YU_Pos);
958 sDate->
Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> RTC_DR_MU_Pos);
959 sDate->
Date = (uint8_t)((datetmpreg & (RTC_DR_DT | RTC_DR_DU)) >> RTC_DR_DU_Pos);
960 sDate->
WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> RTC_DR_WDU_Pos);
963 if (Format == RTC_FORMAT_BIN)
uint8_t RTC_Bcd2ToByte(uint8_t Value)
Convert from 2 digit BCD to Binary.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
◆ HAL_RTC_GetTime()
Get RTC current time.
- 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.
- Parameters
-
| hrtc | RTC handle |
| sTime | Pointer to Time structure with Hours, Minutes and Seconds fields returned with input format (BIN or BCD), also SubSeconds field returning the RTC_SSR register content and SecondFraction field the Synchronous pre-scaler factor to be used for second fraction ratio computation. |
| Format | Specifies 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
-
Definition at line 818 of file stm32l4xx_hal_rtc.c.
832 tmpreg = (uint32_t)(hrtc->
Instance->TR & RTC_TR_RESERVED_MASK);
835 sTime->
Hours = (uint8_t)((tmpreg & (RTC_TR_HT | RTC_TR_HU)) >> RTC_TR_HU_Pos);
836 sTime->
Minutes = (uint8_t)((tmpreg & (RTC_TR_MNT | RTC_TR_MNU)) >> RTC_TR_MNU_Pos);
837 sTime->
Seconds = (uint8_t)((tmpreg & (RTC_TR_ST | RTC_TR_SU)) >> RTC_TR_SU_Pos);
838 sTime->
TimeFormat = (uint8_t)((tmpreg & (RTC_TR_PM)) >> RTC_TR_PM_Pos);
841 if (Format == RTC_FORMAT_BIN)
uint8_t RTC_Bcd2ToByte(uint8_t Value)
Convert from 2 digit BCD to Binary.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
◆ HAL_RTC_SetDate()
Set RTC current date.
- Parameters
-
| hrtc | RTC handle |
| sDate | Pointer to date structure |
| Format | specifies 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
-
Definition at line 862 of file stm32l4xx_hal_rtc.c.
865 HAL_StatusTypeDef status;
875 if ((Format == RTC_FORMAT_BIN) && ((sDate->
Month & 0x10U) == 0x10U))
877 sDate->
Month = (uint8_t)((sDate->
Month & (uint8_t)~(0x10U)) + (uint8_t)0x0AU);
882 if (Format == RTC_FORMAT_BIN)
891 ((uint32_t)sDate->
WeekDay << RTC_DR_WDU_Pos));
899 datetmpreg = ((((uint32_t)sDate->
Year) << RTC_DR_YU_Pos) | \
900 (((uint32_t)sDate->
Month) << RTC_DR_MU_Pos) | \
901 (((uint32_t)sDate->
Date) << RTC_DR_DU_Pos) | \
902 (((uint32_t)sDate->
WeekDay) << RTC_DR_WDU_Pos));
913 hrtc->
Instance->DR = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK);
__IO HAL_RTCStateTypeDef State
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
uint8_t RTC_ByteToBcd2(uint8_t Value)
Convert a 2 digit decimal to BCD format.
uint8_t RTC_Bcd2ToByte(uint8_t Value)
Convert from 2 digit BCD to Binary.
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)
HAL_StatusTypeDef RTC_ExitInitMode(RTC_HandleTypeDef *hrtc)
Exit the RTC Initialization mode.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc)
Enter the RTC Initialization mode.
◆ HAL_RTC_SetTime()
Set RTC current time.
- Parameters
-
| hrtc | RTC handle |
| sTime | Pointer to Time structure |
| Format | Specifies 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
-
Definition at line 708 of file stm32l4xx_hal_rtc.c.
711 HAL_StatusTypeDef status;
730 if (Format == RTC_FORMAT_BIN)
732 if ((hrtc->
Instance->CR & RTC_CR_FMT) != 0U)
748 (((uint32_t)sTime->
TimeFormat) << RTC_TR_PM_Pos));
752 if ((hrtc->
Instance->CR & RTC_CR_FMT) != 0U)
764 tmpreg = (((uint32_t)(sTime->
Hours) << RTC_TR_HU_Pos) | \
765 ((uint32_t)(sTime->
Minutes) << RTC_TR_MNU_Pos) | \
766 ((uint32_t)(sTime->
Seconds) << RTC_TR_SU_Pos) | \
767 ((uint32_t)(sTime->
TimeFormat) << RTC_TR_PM_Pos));
771 hrtc->
Instance->TR = (uint32_t)(tmpreg & RTC_TR_RESERVED_MASK);
774 hrtc->
Instance->CR &= ((uint32_t)~RTC_CR_BKP);
__IO HAL_RTCStateTypeDef State
__HAL_RTC_WRITEPROTECTION_DISABLE(hrtc)
uint8_t RTC_ByteToBcd2(uint8_t Value)
Convert a 2 digit decimal to BCD format.
uint8_t RTC_Bcd2ToByte(uint8_t Value)
Convert from 2 digit BCD to Binary.
__HAL_RTC_WRITEPROTECTION_ENABLE(hrtc)
HAL_StatusTypeDef RTC_ExitInitMode(RTC_HandleTypeDef *hrtc)
Exit the RTC Initialization mode.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
HAL_StatusTypeDef RTC_EnterInitMode(RTC_HandleTypeDef *hrtc)
Enter the RTC Initialization mode.