Is the time in the RTC preserved after hard reset w/o power down?



  • It seems that the RTC from the ESP32 "forgets" the time when a reset is issued. Could be worthwhile to mention it in the docs. If true it makes the use of the RTC sort of worthless in situations where you want to keep time with an attached battery without the possibility to use Wi-Fi to NTP your time like with LoPy or SiPy...

    For completeness

    from machine import RTC
    rtc = RTC()
    this_moment = rtc.now()
    # (1970,....)
    rtc.init( (2017,08,23,10,10,0,0,0) )
    # (2017, ....)
    # press reset button, power still on, even battery
    from machine import RTC
    rtc = RTC()
    this_moment = rtc.now()
    # (1970,....)
    

    One tip: put a RTC chip on the deep_sleep, pysense, pytrack, pywhatever... if one would like to use this in the field on a battery... along with a backup battery for clock (and gps)... Possibly the PIC chip that is used for USB among other things can do some time keeping too....



  • @rolandvs said in Is the time in the RTC preserved after hard reset w/o power down?:

    If true it makes the use of the RTC sort of worthless in situations where you want to keep time with an attached battery without the possibility to use Wi-Fi to NTP your time like with LoPy or SiPy...

    It doesn't solve the original issue, but you can update time without network connection using GPS receiver, e.g. on the pytrack extension board.



  • @loboris

    I would like the RTC to keep running even when a watchdog or reset is necessary and the power (battery) is still on. If the system fails for whatever reason either a watchdog reset or pin-reset should be enough to start again and keep the RTC alive. Deep-sleep is something by choice.

    The ESP32 datasheet and other documents are not very clear in describing what happens. Some bits and pieces: The RTC has a separate power domain (and also supplies the CPU?) (that's good)
    The RTC consists of memory than can be retained, peripherals and ULP processor that can have its own program (also good)
    The watchdog has a RWDT and MWDT. The RWDT resets everything including the RTC. So what is the xxPy using?
    I did not check, but is the xxPy using an external 32kHz crystal "under the hood"?



  • ESP32 RTC time is preserved during deepsleep, and you can wake up after defined time, by external pin, by touch event, or by any activity which can be handled by ULP. If 32.768 kHz crystal is used the time is very accurate, even without it it is still usable. Why would you want to reset the ESP32 by reset pin (and expect the time to be preserved) ?



  • Well I'm spoiled with my PYBoard with the STM32 :-). Disappointing though. Now I use my Pytrack to get the time and set the RTC, but then this is lacking backup power for the GPS so no quick fix functionality.



  • Yes, the RTC on the ESP32, much like almost all micro controllers and computers like the Raspberry Pi loses its time on reset.

    There are ways around this, for example on the LoPy and SiPy you can have your app request the current time as a downlink from the network (won't be as accurate as NTP but good enough for many purposes)

    You can also approximate the time by storing the current into flash before doing a reset or deep sleep and then adding the calculated elapsed time (considering that the Py boards once programmed generally take roughly the same amount of time to restart)

    Or attach one of the many cheap RTC boards via I2C or SPI.

    But true it would have been nice for Pycom to have it on their shields, it's not a massive extra cost on the BOM.



Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.