João Sousa / Mbed 2 deprecated dc_load

Dependencies:   Buffer INA2xx PID mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mcp4725.h Source File

mcp4725.h

00001 #include "mbed.h"
00002 
00003 #define MCP4725_ADDR        0xC0
00004 #define MCP4726_CMD_WRITEDAC            (0x40)  // Writes data to the DAC
00005 #define MCP4726_CMD_WRITEDACEEPROM      (0x60)  // Writes data to the DAC and the EEPROM (persisting the assigned value after reset)
00006 
00007 bool mcp4725_setVoltage(I2C *i2c, uint16_t value, bool eeprom)
00008 {   
00009     uint8_t i2c_read_data[3];
00010     i2c_read_data[0] = eeprom ? MCP4726_CMD_WRITEDACEEPROM : MCP4726_CMD_WRITEDAC;
00011     i2c_read_data[1] = value >> 4;
00012     i2c_read_data[2] = (value & 0x0F) << 4;
00013     return i2c->write(MCP4725_ADDR, (const char *)i2c_read_data, 3);
00014 }