Page 1 of 1

How to ESP-IDF I2C with MCP4716

Posted: Tue Nov 05, 2024 9:10 pm
by gomez9656
I'm using ESP-IDF 5.3 to connect with an MCP4716 through I2C.

If I use the i2c tools example I'm able to see the device with address 0x60. I'm trying to build the command link to write to this register but I'm way lost on how to do it.

Re: How to ESP-IDF I2C with MCP4716

Posted: Wed Nov 06, 2024 10:25 am
by MicroController
Are you using the 'legacy' I2C driver ("i2c.h") or the new one ("i2c_master.h")?
With the new one, you don't have to deal with "cmd links" in this case; you can just use i2c_master_transmit(), like

Code: Select all

uint8_t data[2]; // Holds the two bytes to send. data[0] is transmitted first, then data[1]

data[0] = (<power down bits> << 4)| <data bits d09...d06>;
data[1] = (<data bits d05...d00> << 2);
esp_err_t result = i2c_master_transmit(devhdl, data, 2, portMAX_DELAY); // Send the two bytes from data to the I2C slave

Re: How to ESP-IDF I2C with MCP4716

Posted: Wed Nov 06, 2024 1:40 pm
by gomez9656
I'm indeed using i2c_master.h but I think my right/left shift codes were bad and the DAC wasn't being updated.

I will try your solution