I2C with ESP-IDF vs. esp32-arduino
Posted: Tue Aug 15, 2017 10:59 am
Hello,
I try to read data from a DS3231/DS1307 module using a ESP-WROOM-32. I have a working Arduino code snippet which in general does the following:
Now I wanted to try the same using just the ESP-IDF Framework:
In both scenarios the hardware is exactly the same, but the Arduino code works and the IDF code doesn't. The i2c_master_cmd_begin method just gives a timeout (0x107) as result.
I already found this issue: https://github.com/espressif/esp-idf/issues/680 but I am not sure whether it's the same problem because reading the RTC never works for me (even not the first couple of minutes).
Can somewhere else maybe reproduce this issue or give me a hint what's maybe wrong with the IDF code?
Thank you very much in advance.
Regards,
Thomas
I try to read data from a DS3231/DS1307 module using a ESP-WROOM-32. I have a working Arduino code snippet which in general does the following:
Code: Select all
#define DS3231_I2C_ADDRESS 0x68
Wire.begin();
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
Code: Select all
#define DS3231_ADDR 0x68
// Initialize
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = 21;
conf.scl_io_num = 22;
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
conf.master.clk_speed = 100000;
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_0, &conf));
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_0, conf.mode, 0, 0, 0));
// Read data
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
ESP_ERROR_CHECK(i2c_master_start(cmd));
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, (DS3231_ADDR << 1) | I2C_MASTER_WRITE, 1 /* expect ack */));
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, 0x0, 1));
ESP_ERROR_CHECK(i2c_master_start(cmd));
ESP_ERROR_CHECK(i2c_master_write_byte(cmd, (DS3231_ADDR << 1) | I2C_MASTER_READ, 1 /* expect ack */));
uint8_t data[7];
ESP_ERROR_CHECK(i2c_master_read(cmd, data, 7, 0));
ESP_ERROR_CHECK(i2c_master_stop(cmd));
ESP_ERROR_CHECK(i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000/portTICK_PERIOD_MS));
i2c_cmd_link_delete(cmd);
I already found this issue: https://github.com/espressif/esp-idf/issues/680 but I am not sure whether it's the same problem because reading the RTC never works for me (even not the first couple of minutes).
Can somewhere else maybe reproduce this issue or give me a hint what's maybe wrong with the IDF code?
Thank you very much in advance.
Regards,
Thomas