pcf8591 - Driver for 8-bit ADC and an 8-bit DAC PCF8591

group pcf8591

ESP-IDF driver for 8-bit analog-to-digital conversion and an 8-bit digital-to-analog conversion PCF8591.

Ported from esp-open-rtos

Copyright (c) 2017 Pham Ngoc Thanh pnt239@gmail.com Copyright (c) 2017 Ruslan V. Uss unclerus@gmail.com

BSD Licensed as described in the file LICENSE

Defines

PCF8591_DEFAULT_ADDRESS

Enums

enum pcf8591_input_conf_t

Analog inputs configuration, see datasheet.

Values:

enumerator PCF8591_IC_4_SINGLES

Four single-ended inputs.

enumerator PCF8591_IC_DIFF

Three differential inputs.

enumerator PCF8591_IC_2_SINGLES_DIFF

Two single-ended and differential mixed.

enumerator PCF8591_IC_2_DIFFS

Two differential inputs.

Functions

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

Initialize device descriptor.

Parameters:
  • dev – Device descriptor

  • addr – I2C device address

  • port – I2C port number

  • sda_gpio – GPIO pin for SDA

  • scl_gpio – GPIO pin for SCL

Returns:

ESP_OK on success

esp_err_t pcf8591_free_desc(i2c_dev_t *dev)

Free device descriptor.

Parameters:

dev – Device descriptor

Returns:

ESP_OK on success

esp_err_t pcf8591_read(i2c_dev_t *dev, pcf8591_input_conf_t conf, uint8_t channel, uint8_t *value)

Read input value of an analog pin.

Parameters:
  • dev – Device descriptor

  • conf – Analog inputs configuration

  • channel – Analog channel

  • value[out] Analog value

Returns:

ESP_OK on success

esp_err_t pcf8591_write(i2c_dev_t *dev, uint8_t value)

Write value to analog output.

Parameters:
  • dev – Device descriptor

  • value – DAC value

Returns:

ESP_OK on success