Use of RTC with XTAL and deepsleep

  • I have a few questions regarding use of the RTC (real time clock).

    1. Is there a difference in accuracy and power consumption when using the RTC with XTAL_32KHZ vs. INTERNAL_RC
    2. Will the RTC need to be reinitalized after a deepsleep to make it use XTAL_32KHZ or INTERNAL_RC
    3. Will deep sleep have any affect on the accuracy of the RTC?

  • Hi,

    I'm trying to setup the RTC to use the external XTAL while in deep-sleep. I create an RTC and set its source to XTAL_32KHZ right before entreing the deep-sleep mode. Everything seems to work fine, but accuracy is still a mess (2 seconds diff over a 10-min sleep time), exactly the same as when using the internal RC oscillator.

    It looks like the ESP32 is still using the internal clock, because if I remove the crystal, it does the same.

    My test code:

    import machine
    import time
    rtc = machine.RTC()

    Any thoughts on this? What am I missing?


  • Hi @jardar

    You will get better accuracy - including timing deepsleep wake, especially if you're having long sleep times - using an external crystal at the expense of slightly higher power consumption. I don't however have quantitative data on this to share and it'll also vary depending on the crystal used.

    On the normal firmware you'll need to tell RTC to enable XTAL_32KHZ every time, because the pycom-esp-idf is compiled with


    so this reverts to the internal clock every deepsleep cycle.

    If you're using an external crystal I'd recommend compiling a custom firmware with the external crystal enabled: Component config->ESP32-specific->"Timers used for gettimeofday" and "RTC clock source"

Pycom on Twitter