cancel
Showing results for 
Search instead for 
Did you mean: 

RTC current time in milliseconds (display in 6 byte hex)

kcire L.
Associate III

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

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

In order 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.

View solution in original post

2 REPLIES 2
Peter BENSCH
ST Employee

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

In order 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.
SAsse.1
Associate

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