This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Retaining RTC Time After resetting NRF52840.

Hello Respected members, I have a question regarding the #nrf5-calendar example that is, is there any way to retain the NRF52 time after resetting the device. I am using the nrf_calendar example which is using RTC0 and when I reset the device the time is no longer retained ( which I have set from the GUI). Now my question is, is there any way to retain the time even after resetting the device, should I go for app_timer instead of RTC, or do I have to store the time in flash which holds the values after reset. If flash is the solution then kindly elaborate how would I save time values in flash.
Thanks and regards
Engr. Sami Ul Haq

Parents
  • Hello Sami Ul Haq,

    While it could be possible to store the date to flash, I am not sure that this would be feasible for a calendar application since the device does not know how long it has been in SYSTEM_OFF mode - so if the last thing written to flash was 60 days ago, it will not have any way to know this, and it will resume its RTC as if no time has passed.
    The only thing this would tell is with certainty is that the date and time in flash has passed, at least.

    There is unfortunately no way to resume the RTC and date-time keeping in a more accurate way through a SYSTEM_OFF, since the RTC also is off during this time. My advice would be to connect to the device following a reset, and update / synchronize the calendar time before starting operation again.

    If your application really needs to keep track of the time passed in SYSTEM_OFF sleep you might have to add an external RTC that could do this for you while the nRF is in SYSTEM_OFF sleep.

    Best regards,
    Karl

Reply
  • Hello Sami Ul Haq,

    While it could be possible to store the date to flash, I am not sure that this would be feasible for a calendar application since the device does not know how long it has been in SYSTEM_OFF mode - so if the last thing written to flash was 60 days ago, it will not have any way to know this, and it will resume its RTC as if no time has passed.
    The only thing this would tell is with certainty is that the date and time in flash has passed, at least.

    There is unfortunately no way to resume the RTC and date-time keeping in a more accurate way through a SYSTEM_OFF, since the RTC also is off during this time. My advice would be to connect to the device following a reset, and update / synchronize the calendar time before starting operation again.

    If your application really needs to keep track of the time passed in SYSTEM_OFF sleep you might have to add an external RTC that could do this for you while the nRF is in SYSTEM_OFF sleep.

    Best regards,
    Karl

Children
  • Hello Karl sir,

    Thank you for your reply. I got it but what will be the solution when I know the time for which the device will be in SYSTEM_OFF mode? as you said we do not know the time for which the device will be in SYSTEM_OFF mode. And I have one more thing in mind that is it possible that the time will increment/update after each second in flash.?

    Thanks and Regards,

    Sami Ul Haq

  • Hello again, Sami Ul Haq

    Sami Ul Haq said:
    Thank you for your reply.

    No problem at all, I am happy to help!

    Sami Ul Haq said:
    I got it but what will be the solution when I know the time for which the device will be in SYSTEM_OFF mode? as you said we do not know the time for which the device will be in SYSTEM_OFF mode.

    These statements seems to be conflicting, but if you know exactly how long the device will be in SYSTEM_OFF mode then you may load the previous timestamp from flash, and then increment it with the time it has been in SYSTEM_OFF sleep, yes.

    Sami Ul Haq said:
    I have one more thing in mind that is it possible that the time will increment/update after each second in flash.?

    You can write / update flash every second, but writing to flash both takes time to do, and wears the flash out over time. I am not sure that this would be an ideal solution for keeping time. If I could ask, what will you be using these real-time timestamps for?

    Best regards,
    Karl

  • Hell  sir. Thank you again, I am glad to hear from you.

    I am working on a project named "sports tracker" which will be doing specific work, and I have to set its time from python GUI once, and when I set the time for one time, then the device time is retained even though I press the reset button or the device is in SYSTEM_OFF Mode. Let me talk to the boss about whether we can use an external RTC or not. If external RTC is the last option then definitely we will use external RTC but if there is any other solution I will go for it.

    Thanks, And Regards,

    Sami Ul Haq

  • Hello, Again Karl Ylvisaker Sir.

    Sir can you please tell me, Is the power remains uncut(from the chip or RTC)during reset(button reset)? If No, then RTC must be running during button reset because the power is flowing to the RTC during button reset., right? I am not talking about the SYSTEM_OFF MODE, the device will be in SYSTEM_ON MODE where the RTC will be running, but I am confused about the Reset from the button(Whether RTC stopped or not).  Also can you please elaborate the all possible reset behaviours of NRF52840?

    Kind Regards,

    Sami Ul Haq

  • Hello Sami Ul Haq,

    Sami Ul Haq said:
    I am not talking about the SYSTEM_OFF MODE, the device will be in SYSTEM_ON MODE where the RTC will be running

    Aha - then I have misunderstood you, I thought you were talking about the device being in SYSTEM_OFF mode.
    The RTC will keep running while the device is in SYSTEM_ON mode, no problem. It will have no issue keeping the time as long as it stays in SYSTEM_ON sleep mode.

    Sami Ul Haq said:
    but I am confused about the Reset from the button(Whether RTC stopped or not). 

    The RTC counter will be reset if the device is reset, yes. As you can see in the COUNTER register documentation it is set to 0x0 upon reset.

    Sami Ul Haq said:
    Also can you please elaborate the all possible reset behaviours of NRF52840?

    What exactly would you like me to elaborate on? You can read about the device's reset behavior in the Reset documentation.

    Best regards,
    Karl

Related