I2C now working on IDF-v2.0
Posted: 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");
}
}