How to use the internal RTC on nRF52833 SoC to keep system time across reboots

Hello,

I need your help on how to use the internal RTC on nRF52833 SoC to keep the system time under zypher.

I need the RTC to keep its time after,

1- Reboots

2- Sleep using k_sleep( Duration ) 

3- System Off mode, although this use case may not be necessary but still interested if it is possible.

Finally, looking at the nRF52833 RTC registers I could not find a way of setting the time. Is there one?

Kind regards

Mohamed

Parents Reply Children
  • Thank you.

    I would appreciate it a great deal if you could point me to an example showing how to the persistent registers.

    Also, what does the first line in red mean?

    This information applies to the following SoftDevices: S130, S132, S332

    Note, I am using,

    - nRF52833 SoC

    - SEGGER Embedded Studio for ARM
      Release 5.60  Build 2021081102.47262
      Nordic Edition
      Windows x64

    - Zephyr OS build v2.6.99-ncs1

    - NCS v1.7.0

    Kind regards

    Mohamed

  • Thank you.

    I am assuming the internal RTC in nRF52833 cannot be used for the first two scenarios mentioned above. Is this right?

    I would appreciate it a great deal if you could point me to an example showing how to the persistent registers.

    Oh! I have just noticed there are some code snippets further down the page that show how to use the persistent registers.

    Also, what does the first line in red mean?

    This information applies to the following SoftDevices: S130, S132, S332

    Note, I am using,

    - nRF52833 SoC

    - SEGGER Embedded Studio for ARM
      Release 5.60  Build 2021081102.47262
      Nordic Edition
      Windows x64

    - Zephyr OS build v2.6.99-ncs1

    - NCS v1.7.0

    Kind regards

    Mohamed

  • NRF_UICR_Type n;
    LOG_ERR("NRF_UICR_Type %d", n.CUSTOMER[0]);
    n.CUSTOMER[0]++;

    If you reset MCU you will see that value will be +1

  • Thank you.

    Are you advocating I use the CUSTOMER  area in the UICR to store the time?

    I did think about it but I think it is more of a hack. RTC would be a neater solution. Plus, correct me if I am wrong, I seem to recall that it is not possible for the application firmware to write to the UICR area. Am I right?

    I still would like to know why I cannot use the nRF52833 internal RTC?

    Kind regards

    Mohamed

  • You can only write once to the UICR registers and need to erase the whole UICR if you want any entirely different data to be stored in these registers. So I do not recommend writing to UICR if you need to update this over period of time. Best is to use Settings in Zephyr to write something to the reserved flash page before shutting the core and read from the stored value when waking up. You can still use the read value to add on top of the RTC value to get an essence of tracking the time from the start.

Related