I2C problem with Esp-Idf V4.4-dev-1404

jmcornil
Posts: 21
Joined: Mon Feb 10, 2020 1:42 pm

I2C problem with Esp-Idf V4.4-dev-1404

Postby jmcornil » Thu May 20, 2021 10:22 am

Hello

I am trying to use the latest version (4.4) of esp-idf and I encounter a problem with i2c install

For instance witt the the following program (i2c scan)

Code: Select all

printf("i2c scanner\r\n\r\n");
// configure the i2c controller 0 in master mode, normal speed
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = 14;
conf.scl_io_num = 27;
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
conf.master.clk_speed = 10000;
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_0, &conf));

printf("- i2c controller configured\r\n");

// install the driver
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0));
printf("- i2c driver installed\r\n\r\n");

printf("scanning the bus...\r\n\r\n");

int devices_found = 0;

for(int address = 1; address < 127; address++) {
	// create and execute the command link
	i2c_cmd_handle_t cmd = i2c_cmd_link_create();
	i2c_master_start(cmd);
	i2c_master_write_byte(cmd, (address << 1) | I2C_MASTER_WRITE, true);
	i2c_master_stop(cmd);
	if(i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000 / portTICK_RATE_MS) == ESP_OK) {
		printf("-> found device with address 0x%02x\r\n", address);
		devices_found++;
	}
	i2c_cmd_link_delete(cmd);
}
if(devices_found == 0) printf("\r\n-> no devices found\r\n");
printf("\r\n...scan completed!\r\n");
	
If I compile it with esp-idf version 4.1-dev-2020, it works fine on my ESP32.

But if I compile it with lateste version 4.4-dev-1404, on the same board, I get the message :
"i2C clock choice is invalid, please check flag and frequency"

Has someone any idea ?

Thanks in advance

boarchuz
Posts: 604
Joined: Tue Aug 21, 2018 5:28 am

Re: I2C problem with Esp-Idf V4.4-dev-1404

Postby boarchuz » Thu May 20, 2021 10:53 am

A new member was recently added to i2c_config_t:

https://github.com/espressif/esp-idf/bl ... /i2c.h#L66

You can initialise to 0 for default behaviour (or, even better, initialise the entire struct; any new additions like this will then typically do the backwards-compatible default thing if zeroed).

https://github.com/espressif/esp-idf/bl ... /i2c.h#L43

jmcornil
Posts: 21
Joined: Mon Feb 10, 2020 1:42 pm

Re: I2C problem with Esp-Idf V4.4-dev-1404

Postby jmcornil » Thu May 20, 2021 12:39 pm

Thank you very much @boarchuz

It works fine.

But I do not understand why adding a member to a structure can cause such a problem.

I think ther must be a hidden problem.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: I2C problem with Esp-Idf V4.4-dev-1404

Postby WiFive » Thu May 20, 2021 7:29 pm

The value of an uninitialized local variable in C is indeterminate.

Code: Select all

 i2c_config_t conf;
Any member you don't set like clk_flags will have a random value.

PeterG76
Posts: 17
Joined: Wed May 25, 2022 10:25 am

Re: I2C problem with Esp-Idf V4.4-dev-1404

Postby PeterG76 » Tue Nov 01, 2022 1:15 pm

Thanks for this solution.

I had been tasked with porting an existing application built with ESP-IDF v4.1-beta2 (minGW make) to v4.4 (CMake) and was getting the same error when running my rebuilt application on our ESP32-WROVER-E.
I (1668) HWCI: Creating Front Panel
E (1688) i2c: i2c_param_config(662): i2c clock choice is invalid, please check flag and frequency
I (1698) HWCI: Initialised I2C
E (1728) i2c: i2c_master_write(1168): i2c null address error
E (2728) i2c: i2c_set_pin(860): scl and sda gpio numbers are the same
E (2728) i2c: i2c_master_write(1168): i2c null address error
E (3728) i2c: i2c_set_pin(860): scl and sda gpio numbers are the same
E (3728) i2c: i2c_master_write(1168): i2c null address error
E (4728) i2c: i2c_set_pin(860): scl and sda gpio numbers are the same
E (4728) i2c: i2c_master_write(1168): i2c null address error
E (5728) i2c: i2c_set_pin(860): scl and sda gpio numbers are the same
Setting the i2c_conf_t struct to all zeros in our I2C platform initialization function worked for us .

Who is online

Users browsing this forum: Majestic-12 [Bot] and 91 guests