[solved] Setting RTC register bits fails (ESP32-S3)

cbaurtx
Posts: 14
Joined: Sun May 10, 2020 9:24 am

[solved] Setting RTC register bits fails (ESP32-S3)

Postby cbaurtx » Sat Feb 17, 2024 1:17 pm

I want to initialize the RTC I2C controller using the main processor of the ESP32-S3
As en example setting RTC_I2C_SCL_LOW_REG

SET_PERI_REG_BITS(RTC_I2C_SCL_LOW_REG, RTC_I2C_SCL_LOW_PERIOD_REG, 40, RTC_I2C_SCL_LOW_PERIOD_REG_S); // SCL low/high period = 40, which result driving SCL with 100kHz.
ESP_LOGI(TAG, "RTC_I2C_SCL_LOW_REG = %d", READ_PERI_REG(RTC_I2C_SCL_LOW_REG));

When executing the code the read back returns the default value (256) and not the set value (40).

I use IDF which is part of an ADF installation, IDF Version v4.4-dev-5980-g3c8bc2213c-dirty ADF Version v2.6
Last edited by cbaurtx on Sat Mar 02, 2024 9:06 pm, edited 1 time in total.

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: Setting RTC register bits fails (ESP32-S3)

Postby Sprite » Sun Feb 18, 2024 3:38 am

Hm, that smells like that peripheral or power domain is not enabled. The RTC I2C peripheral is part of the ULP coprocessor; you can see if you somehow can enable that and if that makes the register writable.

cbaurtx
Posts: 14
Joined: Sun May 10, 2020 9:24 am

Re: Setting RTC register bits fails (ESP32-S3)

Postby cbaurtx » Mon Feb 19, 2024 10:13 pm

Thank you for answering that quickly. What you said makes a lot of sense, however I can
use the RTC GPIO without any problems. How can I turn the RTC power domain on or off to
double check?

cbaurtx
Posts: 14
Joined: Sun May 10, 2020 9:24 am

[solved] Re: Setting RTC register bits fails (ESP32-S3)

Postby cbaurtx » Tue Feb 27, 2024 10:13 pm

Code: Untitled.c Select all


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#define TAG "test_write_rtc_reg.c"

#if ESP_IDF_VERSION_MAJOR < 5
#include "driver/rtc_cntl.h"
#else
#include "esp_private/rtc_ctrl.h"
#endif

#include "driver/rtc_io.h"
#include "soc/rtc_i2c_reg.h"
#include "esp_log.h"

int app_main(void) {
#if CONFIG_IDF_TARGET_ESP32
#pragma message "IDF Target ESP32"

SET_PERI_REG_BITS(RTC_I2C_SCL_LOW_PERIOD_REG, RTC_I2C_SCL_LOW_PERIOD, 40, RTC_I2C_SCL_LOW_PERIOD_S);
ESP_LOGI(TAG, "ESP32 RTC_I2C_SCL_LOW_REG = %d", READ_PERI_REG(RTC_I2C_SCL_LOW_PERIOD_REG));

SET_PERI_REG_BITS(RTC_I2C_SCL_LOW_PERIOD_REG, RTC_I2C_SCL_LOW_PERIOD, 20, RTC_I2C_SCL_LOW_PERIOD_S);
ESP_LOGI(TAG, "ESP32 RTC_I2C_SCL_LOW_REG = %d", READ_PERI_REG(RTC_I2C_SCL_LOW_PERIOD_REG));

#endif


#if CONFIG_IDF_TARGET_ESP32S3
#pragma message "IDF Target ESP32-S3"

SET_PERI_REG_BITS(RTC_I2C_SCL_LOW_REG, RTC_I2C_SCL_LOW_PERIOD_REG_M, 40, RTC_I2C_SCL_LOW_PERIOD_REG_S);
ESP_LOGI(TAG, "ESP32S3 RTC_I2C_SCL_LOW_REG = %d", READ_PERI_REG(RTC_I2C_SCL_LOW_REG));

SET_PERI_REG_BITS(RTC_I2C_SCL_LOW_REG, RTC_I2C_SCL_LOW_PERIOD_REG, 20, RTC_I2C_SCL_LOW_PERIOD_REG_S);
ESP_LOGI(TAG, "ESP32S3 RTC_I2C_SCL_LOW_REG = %d", READ_PERI_REG(RTC_I2C_SCL_LOW_REG));

#endif

for(;;);

}
I did some more tests. This code works with an ESP32 but not with an ESP32-S3
With the ESP32-S3 the default value is returned. How are the default values set?
Last edited by cbaurtx on Sat Mar 02, 2024 9:04 pm, edited 1 time in total.

cbaurtx
Posts: 14
Joined: Sun May 10, 2020 9:24 am

Re: Setting RTC register bits fails (ESP32-S3)

Postby cbaurtx » Fri Mar 01, 2024 6:53 pm

Finally I got it working and I blame poor documentation for my problem. Looking how the RiskV ULP initializes the rtc i2c I found this:

Code: Select all

/* For esp32s3, we need to enable the rtc_i2c clock gate before accessing rtc i2c    registers */
  SET_PERI_REG_MASK(SENS_SAR_PERI_CLK_GATE_CONF_REG, SENS_RTC_I2C_CLK_EN);
So insert this at line 34 and the rtc register can be set :)

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: Setting RTC register bits fails (ESP32-S3)

Postby Sprite » Sat Mar 02, 2024 4:58 am

Finally I got it working and I blame poor documentation for my problem.
I entirely agree, I'll see if I can poke the documentation team to include this information in future releases. EDIT: Seems that chapter is the very last chapter in the TRM that is missing. People are working on it.

Who is online

Users browsing this forum: Applebot, GPTBot, Qwantbot and 2 guests