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

Can I use RTC1 to realize the time function(hours, minutes and seconds,day, week,month, yea) and can the RTC1 keep running when in sleep mode?

Can I use RTC1, whitch is used by app_timer for button debounce, ble_conn_params and so on, to realize the time function (hours, minutes, seconds,day, week,month, yea)? And how to realize? Besides, can the RTC1 keep counting when system in sleep mode?

Parents
  • I'm doing this as well.

    The first thing I did was add support for the overflow interrupt and count overflows. I then added code to convert NRF_RTC1->COUNTER and my overflow count to seconds and 32KHz ticks.

    To get the current time you can use the BLE current time service (at least with iOS, not so much with Android) to read the time from the central.

    The date conversion code is a bit fiddly. You can convert the time you get from CTS to seconds since some epoch and then sample the seconds+ticks from the RTC. When you want to sample the wall clock time you do CTSepoch + RTCnow - RTCepoch and convert that to YYYY/MM/DD HH:MM:SS. Alternatively you can take the time data you get from CTS and just advance it periodically.

    I ended up refetching the time from the central whenever the day changes do deal with any accumulated error. The central will also notify my code whenever the timezone changes so you don't have to deal with that.

    The accuracy seems to be okay as long as you are connected, but it isn't overly accurate if not connected. I haven't taken the time to track down the accuracy loss. For example, is the soft device turning off the external LF clock and using the internal LF clock when advertising? Or is the crystal we are using not quite as accurate as it is supposed to be.

Reply
  • I'm doing this as well.

    The first thing I did was add support for the overflow interrupt and count overflows. I then added code to convert NRF_RTC1->COUNTER and my overflow count to seconds and 32KHz ticks.

    To get the current time you can use the BLE current time service (at least with iOS, not so much with Android) to read the time from the central.

    The date conversion code is a bit fiddly. You can convert the time you get from CTS to seconds since some epoch and then sample the seconds+ticks from the RTC. When you want to sample the wall clock time you do CTSepoch + RTCnow - RTCepoch and convert that to YYYY/MM/DD HH:MM:SS. Alternatively you can take the time data you get from CTS and just advance it periodically.

    I ended up refetching the time from the central whenever the day changes do deal with any accumulated error. The central will also notify my code whenever the timezone changes so you don't have to deal with that.

    The accuracy seems to be okay as long as you are connected, but it isn't overly accurate if not connected. I haven't taken the time to track down the accuracy loss. For example, is the soft device turning off the external LF clock and using the internal LF clock when advertising? Or is the crystal we are using not quite as accurate as it is supposed to be.

Children
No Data
Related