Page 1 of 1
[solved] Setting RTC register bits fails (ESP32-S3)
Posted: Sat Feb 17, 2024 1:17 pm
by cbaurtx
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
Re: Setting RTC register bits fails (ESP32-S3)
Posted: Sun Feb 18, 2024 3:38 am
by ESP_Sprite
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.
Re: Setting RTC register bits fails (ESP32-S3)
Posted: Mon Feb 19, 2024 10:13 pm
by cbaurtx
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?
[solved] Re: Setting RTC register bits fails (ESP32-S3)
Posted: Tue Feb 27, 2024 10:13 pm
by cbaurtx
#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?
Re: Setting RTC register bits fails (ESP32-S3)
Posted: Fri Mar 01, 2024 6:53 pm
by cbaurtx
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
Re: Setting RTC register bits fails (ESP32-S3)
Posted: Sat Mar 02, 2024 4:58 am
by ESP_Sprite
cbaurtx wrote: ↑Fri Mar 01, 2024 6:53 pm
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.