32KHz xtal has been stopped - ERROR

manchancleta
Posts: 1
Joined: Thu Jan 02, 2025 4:20 pm

32KHz xtal has been stopped - ERROR

Postby manchancleta » Fri Jan 31, 2025 4:10 pm

Hello,

I'm using a custom board with an external 32 kHz crystal to keep track of time while the system is in deep sleep. It generally seems to work fine, but there are a couple of boards that display the message "32KHz xtal has been stopped" the moment they enter deep sleep.

I use the following code to test only the RTC on the board where it does not work:

Code: Select all

void app_main(void)
{
    // rtc_clk_slow_freq_set(RTC_SLOW_FREQ_RTC);
  
    ESP_LOGI(TAG, "Slow clock source before deep sleep: %d", rtc_clk_slow_freq_get());

    int64_t time_before = rtc_time_get();
    ESP_LOGI(TAG, "RTC time before deep sleep: %lld", time_before);

    // Configure wakeup timer
    esp_sleep_enable_timer_wakeup(5000000); // 5 seconds

    // Force use of 32 kHz crystal
    rtc_clk_32k_enable(true);
    rtc_clk_slow_freq_set(RTC_SLOW_FREQ_32K_XTAL);

    // Keep RTC peripherals powered
    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON);

    // Check crystal status
    bool xtal_32k_status = rtc_clk_32k_enabled();
    ESP_LOGI(TAG, "32kHz crystal is %s", xtal_32k_status ? "ACTIVE" : "INACTIVE");

    ESP_LOGI(TAG, "Slow clock source after configuration: %d", rtc_clk_slow_freq_get());

    esp_deep_sleep_start();
}
The logs show:

Code: Select all

I (495) main_task: Calling app_main()
I (495) rtc_test: Slow clock source before deep sleep: 1
I (505) rtc_test: RTC time before deep sleep: 3131998
I (505) rtc_test: 32kHz crystal is ACTIVE
I (515) rtc_test: Slow clock source after configuration: 1
However, it never wakes up from deep sleep. If I instead use:

Code: Select all

rtc_clk_slow_freq_set(RTC_SLOW_FREQ_RTC);
It works fine. The strange thing is that the boards used to run an Arduino program, which I migrated to ESP-IDF. With this program, everything worked fine. The documentation left behind says it configures the ESP32 via menuconfig to use the external 32 kHz clock, but I don't know if this is correct, since I don't have all the files—just the binaries with the configuration.

Is it possible that the Arduino code was never using the external crystal, or did it switch to using the internal one? There is no mention of this in the code.

ahsrabrifat
Posts: 25
Joined: Sat Jan 18, 2025 2:31 pm

Re: 32KHz xtal has been stopped - ERROR

Postby ahsrabrifat » Sat Feb 01, 2025 3:28 pm

You'd better check your PCB traces. The traces to the 32 kHz crystal must be short and symmetric, and should avoid noisy signals that are likely to interfere.

Who is online

Users browsing this forum: marekdor and 84 guests