I'm porting some code to the ESP32. The app connects to an external RTC https://www.mouser.com/datasheet/2/268/25010A-71550.pdf. I'm trying to convert its primitive functions to the IDF. This is the existing sequence for a register read:
Code: Select all
// uint8_t result = 0;
// SI2C_Start();
// SI2C_WriteByte(I2C_MCP7940_W);
// SI2C_WriteByte(Address);
// SI2C_Restart();
// SI2C_WriteByte(I2C_MCP7940_R);
// result = SI2C_ReadByte();
// SI2C_Acknowledge(1);
// SI2C_Stop();
// return result;
Code: Select all
i2cCommand = i2c_cmd_link_create();
err = i2c_master_start(i2cCommand);
err = i2c_master_write_byte(i2cCommand, I2C_MCP7940_W, true);
err = i2c_master_write_byte(i2cCommand, Address, true);
err = i2c_master_start(i2cCommand);
err = i2c_master_write_byte(i2cCommand, I2C_MCP7940_R, true);
err = i2c_master_read_byte(i2cCommand, &data, I2C_MASTER_ACK);
err = i2c_master_stop(i2cCommand);
err = i2c_master_cmd_begin(I2C_PORT_NBR, i2cCommand, I2C_WAITTIME_TICKS);
i2c_cmd_link_delete(i2cCommand);
I don't understand the need for the restart in the middle, but I've tried it with and without, with same results. Does anyone have an idea what I might be doing wrong here?
Thanks...