set timestamp

Hi,Team,

I'm currently using the nrf54l15-dk. I want to set the rtc of the nrf54l15-dk to obtain the timestamp. How should I configure the timestamp? Which examples should I refer to?
My ncs version is v3.0.2.

The function I want to achieve is: The app will send 8 bytes (13-digit decimal numbers, accurate to milliseconds) of data. I want to set these eight bytes as the time stamp of the nrf54l15-dk, and the app should be able to obtain the real-time time stamp in the format of: YYMM.

Thanks.

  • Hi,

    The System Off sample has the basic framework for entering and waking from system off, and is therefore a good sample to start off of for a prototype. You can enable some statistics in that sample, through configuring CONFIG_APP_USE_RETAINED_MEM=y. However, out-of-the-box that sample only accumulates uptime, and not sleep time.

    In order to get the total time lapsed on the nRF54L15, since system boot, you can use nrfx_grtc_syscounter_get(). It provides the number of microseconds lapsed on the SYSCOUNTER of the GRTC. The GRTC can operate through System Off, and update the SYSCOUNTER accordingly after wake-up from System Off. See Reset behavior for more information on which reset sources resets the GRCT (marked with an 'x' in the table) and which reset sources do not (blank).

    Please note that the accuracy of the GRTC value is subject to the accuracy of the clock source, which in System Off mode will be the internal low frequency timer of the nRF54L15.

    An additional benefit of looking at the System Off sample, is that it also shows how to retain data through System Off. In order to keep track of the time and date, you need to keep track of the time difference between the SYSCOUNTER and the real time and date. In practice, you can do this by storing the time and date when the SYSCOUNTER started. Then add to this time and date the time passed according to SYSCOUNTER in order to get the current time and date.

    For conversion between timestamps and date formats, the best would be to find an existing library. There are way too many pitfalls if trying to implement this on your own, such as time zones, leap years, leap seconds, etc., etc. Typically time and date information is stored in UNIX timestamps, which are the number of seconds passed since January 1st 1970. This should be easy to work with since you do have a seconds counter (or microseconds counter) from the GRTC. There are good libraries (e.g. POSIX) for working on dates, which can convert to and from UNIX timestamps and to and from various time formats.

    Regards,
    Terje

Related