This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF52 SDK 1.6.0 Zephyr , How get and set RTC clock for data and time

Hello,

in my application I need Real Time Clock whit date and time.

How set and get the current date and time.

Where i found an example?

Thanks in avance

Best regards

Parents
  • Hi,

    You can find an example using the nRF RTC timer in zephyr/tests/drivers/timer/nrf_rtc_timer. All RTC peripherals in Zephyr are implemented through Counter with device-specific API, such as the nRF RTC timer.

    Best regards,

    Marte

  • Hi,

    I have seen the example, but I need a more specific example, we are making a new smart watch and I need to set and read the date dd / mm / yyyy and the time hh: mm: ss.

    From the suggested example I can't figure out how to do it. Another example?

    Thanks in advance

    Best Regards

  • Hi,

    The nRF52 does not know the current time by itself, so you must do something to get the current time from an external source, either by the user setting it themselves or from something like a phone. If you want to get the current time from another device, you can use the Current Time Service Client module. This module is used in the Peripheral CTS client sample, where the device reads the current time from a CTS server, such as nRF Connect for Desktop, and prints it on UART. You can change this to instead save this time to a variable, to set the current time.

    You must then keep track of the time elapsed since you got the time from the external source, by using RTC. After this, the current time can be found by adding the elapsed time to the current time you got from the external source. 

    The elapsed time will be reliable over short periods of time, but over longer time the elapsed time from RTC will drift. So if it is important to minimize this drift in your case, you should poll the current time from the external source regularly, for example by getting the current time using the CTS client module.

    Best regards,

    Marte

Reply
  • Hi,

    The nRF52 does not know the current time by itself, so you must do something to get the current time from an external source, either by the user setting it themselves or from something like a phone. If you want to get the current time from another device, you can use the Current Time Service Client module. This module is used in the Peripheral CTS client sample, where the device reads the current time from a CTS server, such as nRF Connect for Desktop, and prints it on UART. You can change this to instead save this time to a variable, to set the current time.

    You must then keep track of the time elapsed since you got the time from the external source, by using RTC. After this, the current time can be found by adding the elapsed time to the current time you got from the external source. 

    The elapsed time will be reliable over short periods of time, but over longer time the elapsed time from RTC will drift. So if it is important to minimize this drift in your case, you should poll the current time from the external source regularly, for example by getting the current time using the CTS client module.

    Best regards,

    Marte

Children
No Data
Related