cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 Real Time Clock - Sub Seconds

Garnett.Robert
Senior III

Hi,

I need to get time from the RTC at a higher resolution than 1 second. I see there are two reg's that set up the thing for sub seconds, but I don't understand how to use them. I really only need tenths of seconds.

I looked at the sub seconds register, but it doesn't seem to be changing.

Regards

Rob

4 REPLIES 4
Bruno_ST
ST Employee

Hello @Garnett.Robert​ ,

Is BYPSHAD=1 (Bypass the shadow registers) ?

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

> I see there are two reg's that set up the thing for sub seconds

Which two? What thing?

The RTC_SSR is simply a downcounter incremented by the asynchronous prescaler's output, and reloaded by the synchronous prescaler. There's nothing particular to be set for it to work, it's simply part of how RTC normally works.

The description of RTC in RM is quite exhausting, try re-reading it.

JW

Garnett.Robert
Senior III

Hi,

When I examine the RTC Subsecond register in the Cube IDE SFR pane the subseconds register doesn't change when I push the RD. However the HAL_rtc_GetTime function returns a changeing value of SubSeconds:

The HAL Get time functions says:

...
  * @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
  * @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.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_RTC_GetTime(RTC_HandleTypeDef *hrtc, RTC_TimeTypeDef *sTime, uint32_t Format)
...

So am I correct in assuming the calculation of a seconds fractional part is:

secondsFraction = (float)((sTime.SecondFraction - sTime.SubSeconds) / 
                               (float)(sTime.SecondFraction+1)

The statement:

This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS

Do I have to worry about this or are the values returned by the HAL driver valid without me checking for this condition?

Best Regards

Rob

> When I examine the RTC Subsecond register in the Cube IDE SFR pane the subseconds register doesn't change

As Bruno_ST said, this is probably consequence of the shadowing mechanism, which can be switched off and on using the BYPSHAD bit.

As subseconds are part of the shadowing, you have to follow its rules and avoid its pitfalls. I don't know if the shadow/locking erratum ("RTC calendar registers are not locked properly") applies to your STM32 model - check in errata for your particular STM32 - but if yes, reading out all 3 timekeeping registers consistently requires to follow the erratum's guideline.

> This conversion can be performed only if no shift operation is pending (ie. SHFP=0) when PREDIV_S >= SS

 > Do I have to worry about this or are the values returned by the HAL driver valid without me checking for this condition?

Shift does not occur spontaneously, it is your program which would start a shift (in order to fine-adjust time to some precise time source). So as long as you don't start such operation, you don't need to worry.

JW