2022-03-22 04:50 AM
Hello,
I am using an STM32WB55 and am trying to figure out how to get the current time including milliseconds using an RTC and display that time in 6 byte hex format.
I would most likely call the GetTime() based of a millisecond timer if that is the most efficient way to do it.
For example I would like the time to return like this (0x017FB1731312)
Any help or example on this would really be appreciated.
Thanks in advance!
Solved! Go to Solution.
2022-03-22 08:28 AM
This won't work because you can't get millisecond information from the RTC if you have a 32.768kHz (2^15 Hz) crystal connected, which can't be divided down to 1kHz using an integer value.
There is only the counting down subsecond counter RTC_SSR, which is by default set to 256 at 32.768kHz.
If you want millisecond information, it makes most sense to use a timer and process this information with it. In principle, you can also use the systick timer, which triggers an interrupt every 1ms by default.
However, I am not aware of a ready-made proposal for your requirements for any of the options.
Does it answer your question?
Regards
/Peter
2022-03-22 08:28 AM
This won't work because you can't get millisecond information from the RTC if you have a 32.768kHz (2^15 Hz) crystal connected, which can't be divided down to 1kHz using an integer value.
There is only the counting down subsecond counter RTC_SSR, which is by default set to 256 at 32.768kHz.
If you want millisecond information, it makes most sense to use a timer and process this information with it. In principle, you can also use the systick timer, which triggers an interrupt every 1ms by default.
However, I am not aware of a ready-made proposal for your requirements for any of the options.
Does it answer your question?
Regards
/Peter
2023-04-25 07:02 AM
What I am using is one of the 2 RTC Alarm that I configure for 1 sec call back. In the call back function I clear a public variable. That variable gets incremented in the 1 ms SysTick interrupt.
The reason we need to use SyTick is to get milliseconds counter.
The reason we need to use RTC is to synchronize the counting of milllisecond above to the change in seconds.
Note: I use: Counter %= 1000; // to make sure millisec always fall in [0..999] range