2015-12-15 11:55 PM
Hi,
I just noticed something strange using the RTC of STM32F407 with CUBE HAL Library. When calling HAL_RTC_SetTime(); I see no register writes are performed for the SecondFraction field of the RTC_TimeTypeDef structure reference I pass as an argument. Am I missing something? Am I not able to set the second fraction to 999. It always returns as 255. My Cube HAL library version is 1.10.0 by the way. Looking through the cube reference rev 3, page 666 :) (RCT_TimeTypeDef Data Fields) the Field Documentation section mentions the situation as below: uint32_t RTC_TimeTypeDef::SecondFraction Specifies the range or granularity of Sub Second register content corresponding to Synchronous pre-scaler factor value (PREDIV_S) This parameter corresponds to a time unit range between [0-1] Second with [1 Sec / SecondFraction +1] granularity. This field will be used only by HAL_RTC_GetTime function Well my question stands. How do I get a millisecond granularity then? Thanks in advance for all the support. Best Regards, Emre #rtc-cube2015-12-16 12:45 AM
> Well my question stands. How do I get a millisecond granularity then?
Unless you use some highly non-standard crystal (such as 32000.00Hz), you don't. It's not the purpose of RTC to provide millisecond granularity. You could get granularity in multiples of crystal's period multiplied by the asynchronous prescaler's factor. You may decrease the asynchronous prescaler to decrease granularity, but note that that increases VBAT consumption. The RTC chapter in RM goes into painful details, please read it if you intend to use the RTC in a nonstandard way. I don't comment on Cube/CubeMX, I don't use it. JW2015-12-21 11:43 PM
Hi waclawek.jan,
Thanks for directing me to a better point of view on the subject. Best Regards, Emre2015-12-22 08:49 AM
May be it's a HAL issue, several people have complained about it in recent months. From a HW perspective the fractional second portion of the RTC functions as documented.
I don't think you get to write to the prescaler's counter, you likely have to synchronize your writes to the RTC registers to the top-of-second to get the alignment you desire.