0

I have MAX31341 RTC connected to ESP32 over I2C. Connection works, I can set and get time, but for unknown reason, hour register counts hours from 0 to 31:

E (3888) main: RTC time: 2022-08-22 23:59:12
E (63888) main: RTC time: 2022-08-22 24:00:12
E (123888) main: RTC time: 2022-08-22 24:01:12
E (183888) main: RTC time: 2022-08-22 24:02:11
E (243888) main: RTC time: 2022-08-22 24:03:11

This is my first RTC integration, so it is possible that I'm doing something wrong, but after a lot of tests I have no idea what.

MAX31341 rtc(I2C_NUM_0,MAX31341_I2C_ADDRESS);
void setupRTC()
{
    esp_err_t rc;
    struct timeval tv;
    i2c_config_t conf = {
        .mode = I2C_MODE_MASTER,
        .sda_io_num = 21,
        .scl_io_num = 22,
        .sda_pullup_en = GPIO_PULLUP_ENABLE,
        .scl_pullup_en = GPIO_PULLUP_ENABLE,
        .master = {
            .clk_speed = 400000
        },
        .clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL
    };
    rc = i2c_param_config(I2C_NUM_0, &conf);
    if( rc != ESP_OK )
        ESP_LOGE(TAG,"i2c_param_config failed, rc=%d", rc);
    rc = i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
    if( rc != ESP_OK )
        ESP_LOGE(TAG,"i2c_driver_install failed, rc=%d", rc);
    rtc.begin();
}

int main()
{
    // rtc.set_time( '2022-08-22 23:59:12' );
    while(1)
    {
        int ret = rtc.get_time(&rtc_ctime);
        if (ret)
          ESP_LOGE( TAG, "get_time failed!");
        else
        {
            char buf[64];
            strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &rtc_ctime);
            ESP_LOGE( TAG, "RTC time: %s", buf );
        }
        sleep(60);
    }
    return 0;
}

MAX31341 code, comes from Arduino MaxEssentialToolkit v1.0.1 with read and write register functions, replaced with esp-idf substitutes.

Jarek
  • 329
  • 2
  • 13
  • 1
    It's very difficult to give any advice here without seeing the code that demonstrates this problem. Please post a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) that shows the problem. In this case it would be a small, complete program that other people could run that had only the code in it needed to show this problem. – romkey Aug 22 '22 at 17:50
  • 1
    I'm not trying to be a nag here, but you said you modified the code that reads and writes the registers... if I were debugging this I would start with that and the initialization (`begin`) code. That's why I asked for a [minimal, reproducible](https://stackoverflow.com/help/minimal-reproducible-example) example, which would also let people who are trying to help build the program and explore the problem. – romkey Aug 22 '22 at 21:19

0 Answers0