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
[solved] Setting RTC register bits fails (ESP32-S3)
[solved] Setting RTC register bits fails (ESP32-S3)
Last edited by cbaurtx on Sat Mar 02, 2024 9:06 pm, edited 1 time in total.
-
- Posts: 9709
- Joined: Thu Nov 26, 2015 4:08 am
Re: Setting RTC register bits fails (ESP32-S3)
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)
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?
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)
- #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(;;);
- }
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.
Re: Setting RTC register bits fails (ESP32-S3)
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:
So insert this at line 34 and the rtc register can be set
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);
-
- Posts: 9709
- Joined: Thu Nov 26, 2015 4:08 am
Re: Setting RTC register bits fails (ESP32-S3)
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: No registered users and 303 guests