I2C now working on IDF-v2.0

gregstewart90
Posts: 59
Joined: Thu Jan 19, 2017 5:17 pm

I2C now working on IDF-v2.0

Postby gregstewart90 » Fri Apr 14, 2017 6:49 pm

I am using two MCP23017 port expanders on the ESP32. Everything was working great until I upgraded my idf to v2.0. My code no longer controls my MCP23017's, and it doesn't throw any errors. The pins on the MCP23017 don't change, and I get random values back from the read. Below I have code for my read and write. I switched back to my original IDF and the code works just fine. Not sure if this is a bug or if I need to change something in my code to be compatible with the new IDF.

Code: Select all

void mcp23017_duel_write(uint8_t MCP23017_ADDRESS, uint8_t command, uint8_t command2){

	i2c_cmd_handler = i2c_cmd_link_create();
	i2c_master_start(i2c_cmd_handler);
	i2c_master_write_byte(i2c_cmd_handler, MCP23017_ADDRESS << 1 | WRITE_BIT, ACK_CHECK_EN);
	i2c_master_write_byte(i2c_cmd_handler, command, ACK_CHECK_EN);// Access IODIRB
	i2c_master_write_byte(i2c_cmd_handler, command2, ACK_CHECK_EN);// Write Register
	i2c_master_stop(i2c_cmd_handler);
	int ret = i2c_master_cmd_begin(I2C_NUM_1, i2c_cmd_handler, 1000 / portTICK_RATE_MS);
	i2c_cmd_link_delete(i2c_cmd_handler);
	if (ret == ESP_FAIL) {
		printf("ERROR\n");
	}
}

void mcp23017_local_write(uint8_t MCP23017_ADDRESS, uint8_t command){

	vTaskDelay(30 / portTICK_RATE_MS);
	i2c_cmd_handler = i2c_cmd_link_create();
	i2c_master_start(i2c_cmd_handler);
	i2c_master_write_byte(i2c_cmd_handler, MCP23017_ADDRESS << 1 | WRITE_BIT, ACK_CHECK_EN);
	i2c_master_write_byte(i2c_cmd_handler, command, ACK_CHECK_EN);// Access IODIRB
	i2c_master_stop(i2c_cmd_handler);
	int ret = i2c_master_cmd_begin(I2C_NUM_1, i2c_cmd_handler, 1000 / portTICK_RATE_MS);
	i2c_cmd_link_delete(i2c_cmd_handler);
	if (ret == ESP_FAIL) {
		printf("ERROR\n");
	}
}

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: I2C now working on IDF-v2.0

Postby kolban » Sat Apr 15, 2017 8:55 pm

Are you able to attach a logic analyzer to the bus to see what is being transmitted and received?
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

Who is online

Users browsing this forum: No registered users and 88 guests