[SOLVED] 32KHz xtal has been stopped - ERROR

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

[SOLVED] 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.
Last edited by manchancleta on Mon Mar 17, 2025 12:25 pm, edited 1 time in total.

ahsrabrifat
Posts: 201
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.

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

Re: 32KHz xtal has been stopped - ERROR

Postby manchancleta » Fri Mar 14, 2025 3:22 pm

For the record, it seems like a well-known issue in older revisions of the ESP32, although I couldn't find it right away. The microcontroller has a hard time maintaining the crystal running when it enters deep sleep mode. Sometimes it shows the "32KHz xtal had been stopped" error and crashes, other times it just doesn't wake up. The solution is to change the following command in the menuconfig (it was right there...):

Additional current for external 32kHz crystal: Method 2

KCONFIG Name: RTC_EXT_CRYST_ADDIT_CURRENT_METHOD

With some 32kHz crystal configurations, the X32N and X32P pins may not have enough drive strength to keep the crystal oscillating. Choose the method to provide additional current from touchpad 9 to the external 32kHz crystal. Note that the deep sleep current is slightly high (4-5uA) and the touchpad and the wakeup sources of both touchpad and ULP are not available in method 1 and method 2.

This problem is fixed in ESP32 ECO 3, so this workaround is not needed. Setting the project configuration to minimum revision ECO3 will disable this option, allow all wakeup sources, and save some code size.

- "None" option will not provide additional current to external crystal - "Method 1" option can't ensure 100% to solve the external 32k crystal start failed issue, but the touchpad can work in this method. - "Method 2" option can solve the external 32k issue, but the touchpad can't work in this method.

I changed this, and the error didn't occur anymore. I haven't tested if the current consumption in deep sleep has increased.

Who is online

Users browsing this forum: ChatGPT-User, Qwantbot, trendictionbot and 2 guests