How to ESP-IDF I2C with MCP4716

gomez9656
Posts: 21
Joined: Mon Mar 14, 2022 7:48 pm

How to ESP-IDF I2C with MCP4716

Postby gomez9656 » Tue Nov 05, 2024 9:10 pm

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.
Attachments
Screenshot 2024-11-05 161025.png
Screenshot 2024-11-05 161025.png (176.51 KiB) Viewed 702 times

MicroController
Posts: 1733
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: How to ESP-IDF I2C with MCP4716

Postby MicroController » Wed Nov 06, 2024 10:25 am

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

gomez9656
Posts: 21
Joined: Mon Mar 14, 2022 7:48 pm

Re: How to ESP-IDF I2C with MCP4716

Postby gomez9656 » Wed Nov 06, 2024 1:40 pm

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

Who is online

Users browsing this forum: Google [Bot] and 79 guests