Use this forum to chat about hardware specific topics for the ESP8266 (peripherals, memory, clocks, JTAG, programming)

User avatar
By davydnorris
#85631 Yes this is documented behaviour - both system clock and RTC clock are reset after deep sleep, but the RTC memory is retained.

For light sleep the system clock is reset but the RTC clock is not.

For modem sleep neither clock is reset.

The built in RTC is actually not very accurate - it is affected a lot by temperature, which is why there is a calibration function in the SDK. The problem is that the moment the chip goes into deep sleep it starts to cool down and the timing starts to drift.

If you really need accurate timing then you need to use an external RTC, or connect to an sntp server when you wake up. Even when the chip is awake I use the system clock for my timing as it is way more accurate than the RTC.
User avatar
By php fan
#85632
davydnorris wrote:Yes this is documented behaviour - both system clock and RTC clock are reset after deep sleep,

Documented but nevertheless a plain wrong design.

There's an RTC that keeps track of time during deep sleep, and yet the software destroys that valuable information for no good reason.


but the RTC memory is retained.

Unfortunately that's of no help in order to know how long the deep sleep has been, nor does it provide a way to even distinguish whether we woke up automatically or by external reset during deep sleep.

The built in RTC is actually not very accurate


I know, it's terribly inaccurate, but even so it's accurate enough for my application, so it enrages me that I have to add extra hardware to obtain information that was already there in the first place but someone decided it was a good idea to erase.
User avatar
By RichardS
#85684 rtc_get_reset_reason() look this up
User avatar
By php fan
#85692
RichardS wrote:rtc_get_reset_reason() look this up


Thank you but I already had.
It returns "deep sleep wake" regardless of whether the chip woke up automatically after deepsleep at the scheduled time because of the timer, or it got woken up by externally shorting RST to ground. Those two cases are indistinguishable from each other. You only get "external reset" when you reset by grounding RST during program execution.
You could easily distinguish between the two cases (and additionally know "exactly" how long the board has been in deep sleep as opposed to the scheduled period) if the RTC weren't reset at boot. But Espressif went "Hey, there's some valuable information there, let's erase every trace of it at boot time and make sure nobody can use it".