mcp342x - Driver for 18-Bit, delta-sigma ADC MCP3426/MCP3427/MCP3428

group mcp342x

ESP-IDF driver for 18-Bit, multi-channel delta-sigma ADC MCP3426/MCP3427/MCP3428.

Copyright (C) 2020 Ruslan V. Uss unclerus@gmail.com

BSD Licensed as described in the file LICENSE

Defines

MCP342X_ADDR_MIN
MCP342X_ADDR_MAX

Enums

enum mcp342x_mode_t

Device operation mode.

Values:

enumerator MCP342X_ONESHOT

One-shot conversion mode.

enumerator MCP342X_CONTINUOUS

Continuous conversions mode, default.

enum mcp342x_channel_t

Input channel.

Values:

enumerator MCP342X_CHANNEL1

Channel 1, default.

enumerator MCP342X_CHANNEL2

Channel 2.

enumerator MCP342X_CHANNEL3

Channel 3 (MCP3428 only, treated as channel 1 by the MCP3426/MCP3427)

enumerator MCP342X_CHANNEL4

Channel 4 (MCP3428 only, treated as channel 2 by the MCP3426/MCP3427)

enum mcp342x_resolution_t

Resolution.

Values:

enumerator MCP342X_RES_12

12 bits, 240 samples per second

enumerator MCP342X_RES_14

14 bits, 60 samples per second

enumerator MCP342X_RES_16

16 bits, 15 samples per second

enumerator MCP342X_RES_18

18 bits, 3.75 samples per second

enum mcp342x_gain_t

PGA gain.

Values:

enumerator MCP342X_GAIN1

x1, default

enumerator MCP342X_GAIN2

x2

enumerator MCP342X_GAIN4

x4

enumerator MCP342X_GAIN8

x8

Functions

esp_err_t mcp342x_init_desc(mcp342x_t *dev, i2c_port_t port, uint8_t addr, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptior.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • port: I2C port

  • addr: Device address

  • sda_gpio: SDA GPIO pin

  • scl_gpio: SCL GPIO pin

esp_err_t mcp342x_free_desc(mcp342x_t *dev)

Free device descriptor.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t mcp342x_set_config(mcp342x_t *dev)

Configure device.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t mcp342x_get_config(mcp342x_t *dev)

Read device configuration.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t mcp342x_get_sample_time_us(mcp342x_t *dev, uint32_t *us)

Get conversion time in microseconds.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] us: Conversion time, us

esp_err_t mcp342x_start_conversion(mcp342x_t *dev)

Start conversion.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t mcp342x_get_data(mcp342x_t *dev, int32_t *data, bool *ready)

Get raw ADC value.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] data: ADC value

  • [out] ready: Data validity flag

esp_err_t mcp342x_get_voltage(mcp342x_t *dev, float *volts, bool *ready)

Get ADC voltage.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] volts: ADC voltage, volts

  • [out] ready: Data validity flag

esp_err_t mcp342x_oneshot_conversion(mcp342x_t *dev, int32_t *data)

Do a single converiton.

  • start conversion

  • wait convertion time

  • read conversion result

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] data: ADC value

struct mcp342x_t
#include <mcp342x.h>

Device descriptor.