mcp4725 - Driver for 12-bit DAC MCP4725

group mcp4725

ESP-IDF Driver for 12-bit DAC MCP4725.

Ported from esp-open-rtos

Copyright (C) 2016, 2019 Ruslan V. Uss unclerus@gmail.com

BSD Licensed as described in the file LICENSE

Defines

MCP4725A0_I2C_ADDR0
MCP4725A0_I2C_ADDR1
MCP4725A1_I2C_ADDR0
MCP4725A1_I2C_ADDR1
MCP4725A2_I2C_ADDR0
MCP4725A2_I2C_ADDR1
MCP4725_MAX_VALUE

Enums

enum mcp4725_power_mode_t

Power mode, see datasheet.

Values:

enumerator MCP4725_PM_NORMAL

Normal mode.

enumerator MCP4725_PM_PD_1K

Power down, 1kOhm resistor to ground.

enumerator MCP4725_PM_PD_100K

Power down, 100kOhm resistor to ground.

enumerator MCP4725_PM_PD_500K

Power down, 500kOhm resistor to ground.

Functions

esp_err_t mcp4725_init_desc(i2c_dev_t *dev, i2c_port_t port, uint8_t addr, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptor.

Default SCL frequency is 1MHz

Parameters
  • dev – I2C device descriptor

  • port – I2C port number

  • addr – I2C address,

  • sda_gpio – SDA GPIO

  • scl_gpio – SCL GPIO

Returns

ESP_OK on success

esp_err_t mcp4725_free_desc(i2c_dev_t *dev)

Free device descriptor.

Parameters

dev – I2C device descriptor

Returns

ESP_OK on success

esp_err_t mcp4725_eeprom_busy(i2c_dev_t *dev, bool *busy)

Get device EEPROM status.

Parameters
  • dev – I2C device descriptor

  • busy – true when EEPROM is busy

Returns

ESP_OK on success

esp_err_t mcp4725_get_power_mode(i2c_dev_t *dev, bool eeprom, mcp4725_power_mode_t *mode)

Get power mode.

Parameters
  • dev – I2C device descriptor

  • eeprom – Read power mode from EEPROM if true

  • [out] mode – Power mode

Returns

ESP_OK on success

esp_err_t mcp4725_set_power_mode(i2c_dev_t *dev, bool eeprom, mcp4725_power_mode_t mode)

Set power mode.

Parameters
  • dev – I2C device descriptor

  • mode – Power mode

  • eeprom – Store mode to device EEPROM if true

Returns

ESP_OK on success

esp_err_t mcp4725_get_raw_output(i2c_dev_t *dev, bool eeprom, uint16_t *value)

Get current DAC value.

Parameters
  • dev – I2C device descriptor

  • eeprom – Read value from device EEPROM if true

  • [out] value – Raw output value, 0..4095

Returns

ESP_OK on success

esp_err_t mcp4725_set_raw_output(i2c_dev_t *dev, uint16_t value, bool eeprom)

Set DAC output value.

Parameters
  • dev – I2C device descriptor

  • value – Raw output value, 0..4095

  • eeprom – Store value to device EEPROM if true

Returns

ESP_OK on success

esp_err_t mcp4725_get_voltage(i2c_dev_t *dev, float vdd, bool eeprom, float *voltage)

Get current DAC output voltage.

Parameters
  • dev – I2C device descriptor

  • vdd – Device operating voltage, volts

  • eeprom – Read voltage from device EEPROM if true

  • [out] voltage – Current output voltage, volts

Returns

ESP_OK on success

esp_err_t mcp4725_set_voltage(i2c_dev_t *dev, float vdd, float value, bool eeprom)

Set DAC output voltage.

Parameters
  • dev – I2C device descriptor

  • vdd – Device operating voltage, volts

  • value – Output value, volts

  • eeprom – Store value to device EEPROM if true

Returns

ESP_OK on success