ads111x - Driver for ADS1113/ADS1114/ADS1115 and ADS1013/ADS1014/ADS1015 I2C ADC
- group ads111x
ESP-IDF driver for ADS1113/ADS1114/ADS1115, ADS1013/ADS1014/ADS1015 I2C ADC.
Version: 1.1.2
Ported from esp-open-rtos
Copyright (c) 2016, 2018 Ruslan V. Uss unclerus@gmail.com Copyright (c) 2020 Lucio Tarantino https://github.com/dianlight
BSD Licensed as described in the file LICENSE
Defines
-
ADS111X_ADDR_GND
I2C device address with ADDR pin connected to ground.
-
ADS111X_ADDR_VCC
I2C device address with ADDR pin connected to VCC.
-
ADS111X_ADDR_SDA
I2C device address with ADDR pin connected to SDA.
-
ADS111X_ADDR_SCL
I2C device address with ADDR pin connected to SCL.
-
ADS111X_MAX_VALUE
Maximum ADC value.
-
ADS101X_MAX_VALUE
-
ADS101X_DATA_RATE_128
-
ADS101X_DATA_RATE_250
-
ADS101X_DATA_RATE_490
-
ADS101X_DATA_RATE_920
-
ADS101X_DATA_RATE_1600
-
ADS101X_DATA_RATE_2400
-
ADS101X_DATA_RATE_3300
Enums
-
enum ads111x_gain_t
Gain amplifier.
Values:
-
enumerator ADS111X_GAIN_6V144
+-6.144V
-
enumerator ADS111X_GAIN_4V096
+-4.096V
-
enumerator ADS111X_GAIN_2V048
+-2.048V (default)
-
enumerator ADS111X_GAIN_1V024
+-1.024V
-
enumerator ADS111X_GAIN_0V512
+-0.512V
-
enumerator ADS111X_GAIN_0V256
+-0.256V
-
enumerator ADS111X_GAIN_0V256_2
+-0.256V (same as ADS111X_GAIN_0V256)
-
enumerator ADS111X_GAIN_0V256_3
+-0.256V (same as ADS111X_GAIN_0V256)
-
enumerator ADS111X_GAIN_6V144
-
enum ads111x_mux_t
Input multiplexer configuration (ADS1115 only)
Values:
-
enumerator ADS111X_MUX_0_1
positive = AIN0, negative = AIN1 (default)
-
enumerator ADS111X_MUX_0_3
positive = AIN0, negative = AIN3
-
enumerator ADS111X_MUX_1_3
positive = AIN1, negative = AIN3
-
enumerator ADS111X_MUX_2_3
positive = AIN2, negative = AIN3
-
enumerator ADS111X_MUX_0_GND
positive = AIN0, negative = GND
-
enumerator ADS111X_MUX_1_GND
positive = AIN1, negative = GND
-
enumerator ADS111X_MUX_2_GND
positive = AIN2, negative = GND
-
enumerator ADS111X_MUX_3_GND
positive = AIN3, negative = GND
-
enumerator ADS111X_MUX_0_1
-
enum ads111x_data_rate_t
Data rate.
Values:
-
enumerator ADS111X_DATA_RATE_8
8 samples per second
-
enumerator ADS111X_DATA_RATE_16
16 samples per second
-
enumerator ADS111X_DATA_RATE_32
32 samples per second
-
enumerator ADS111X_DATA_RATE_64
64 samples per second
-
enumerator ADS111X_DATA_RATE_128
128 samples per second (default)
-
enumerator ADS111X_DATA_RATE_250
250 samples per second
-
enumerator ADS111X_DATA_RATE_475
475 samples per second
-
enumerator ADS111X_DATA_RATE_860
860 samples per second
-
enumerator ADS111X_DATA_RATE_8
-
enum ads111x_mode_t
Operational mode.
Values:
-
enumerator ADS111X_MODE_CONTINUOUS
Continuous conversion mode.
-
enumerator ADS111X_MODE_SINGLE_SHOT
Power-down single-shot mode (default)
-
enumerator ADS111X_MODE_CONTINUOUS
-
enum ads111x_comp_mode_t
Comparator mode (ADS1114 and ADS1115 only)
Values:
-
enumerator ADS111X_COMP_MODE_NORMAL
Traditional comparator with hysteresis (default)
-
enumerator ADS111X_COMP_MODE_WINDOW
Window comparator.
-
enumerator ADS111X_COMP_MODE_NORMAL
-
enum ads111x_comp_polarity_t
Comparator polarity (ADS1114 and ADS1115 only)
Values:
-
enumerator ADS111X_COMP_POLARITY_LOW
Active low (default)
-
enumerator ADS111X_COMP_POLARITY_HIGH
Active high.
-
enumerator ADS111X_COMP_POLARITY_LOW
-
enum ads111x_comp_latch_t
Comparator latch (ADS1114 and ADS1115 only)
Values:
-
enumerator ADS111X_COMP_LATCH_DISABLED
Non-latching comparator (default)
-
enumerator ADS111X_COMP_LATCH_ENABLED
Latching comparator.
-
enumerator ADS111X_COMP_LATCH_DISABLED
-
enum ads111x_comp_queue_t
Comparator queue.
Values:
-
enumerator ADS111X_COMP_QUEUE_1
Assert ALERT/RDY pin after one conversion.
-
enumerator ADS111X_COMP_QUEUE_2
Assert ALERT/RDY pin after two conversions.
-
enumerator ADS111X_COMP_QUEUE_4
Assert ALERT/RDY pin after four conversions.
-
enumerator ADS111X_COMP_QUEUE_DISABLED
Disable comparator (default)
-
enumerator ADS111X_COMP_QUEUE_1
Functions
-
esp_err_t ads111x_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 – 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 ads111x_free_desc(i2c_dev_t *dev)
Free device descriptor.
- Parameters:
dev – Device descriptor
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_is_busy(i2c_dev_t *dev, bool *busy)
Get device operational status.
- Parameters:
dev – Device descriptor
busy – [out] True when device performing conversion
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_start_conversion(i2c_dev_t *dev)
Begin a single conversion.
Only in single-shot mode.
- Parameters:
dev – Device descriptor
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_get_value(i2c_dev_t *dev, int16_t *value)
Read last conversion result.
- Parameters:
dev – Device descriptor
value – [out] Last conversion result
- Returns:
ESP_OK
on success
-
esp_err_t ads101x_get_value(i2c_dev_t *dev, int16_t *value)
Read last conversion result for ADS101x.
- Parameters:
dev – Device descriptor
value – [out] Last conversion result
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_get_gain(i2c_dev_t *dev, ads111x_gain_t *gain)
Read the programmable gain amplifier configuration.
ADS1114 and ADS1115 only. Use ads111x_gain_values[] for real voltage.
- Parameters:
dev – Device descriptor
gain – [out] Gain value
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_set_gain(i2c_dev_t *dev, ads111x_gain_t gain)
Configure the programmable gain amplifier.
ADS1114 and ADS1115 only.
- Parameters:
dev – Device descriptor
gain – Gain value
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_get_input_mux(i2c_dev_t *dev, ads111x_mux_t *mux)
Read the input multiplexer configuration.
ADS1115 only.
- Parameters:
dev – Device descriptor
mux – [out] Input multiplexer configuration
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_set_input_mux(i2c_dev_t *dev, ads111x_mux_t mux)
Configure the input multiplexer configuration.
ADS1115 only.
- Parameters:
dev – Device descriptor
mux – Input multiplexer configuration
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_get_mode(i2c_dev_t *dev, ads111x_mode_t *mode)
Read the device operating mode.
- Parameters:
dev – Device descriptor
mode – [out] Device operating mode
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_set_mode(i2c_dev_t *dev, ads111x_mode_t mode)
Set the device operating mode.
- Parameters:
dev – Device descriptor
mode – Device operating mode
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_get_data_rate(i2c_dev_t *dev, ads111x_data_rate_t *rate)
Read the data rate.
- Parameters:
dev – Device descriptor
rate – [out] Data rate
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_set_data_rate(i2c_dev_t *dev, ads111x_data_rate_t rate)
Configure the data rate.
- Parameters:
dev – Device descriptor
rate – Data rate
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_get_comp_mode(i2c_dev_t *dev, ads111x_comp_mode_t *mode)
Get comparator mode.
ADS1114 and ADS1115 only.
- Parameters:
dev – Device descriptor
mode – [out] Comparator mode
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_set_comp_mode(i2c_dev_t *dev, ads111x_comp_mode_t mode)
Set comparator mode.
ADS1114 and ADS1115 only.
- Parameters:
dev – Device descriptor
mode – Comparator mode
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_get_comp_polarity(i2c_dev_t *dev, ads111x_comp_polarity_t *polarity)
Get polarity of the comparator output pin ALERT/RDY.
ADS1114 and ADS1115 only.
- Parameters:
dev – Device descriptor
polarity – [out] Comparator output pin polarity
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_set_comp_polarity(i2c_dev_t *dev, ads111x_comp_polarity_t polarity)
Set polarity of the comparator output pin ALERT/RDY.
ADS1114 and ADS1115 only.
- Parameters:
dev – Device descriptor
polarity – Comparator output pin polarity
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_get_comp_latch(i2c_dev_t *dev, ads111x_comp_latch_t *latch)
Get comparator output latch mode.
ADS1114 and ADS1115 only.
- Parameters:
dev – Device descriptor
latch – [out] Comparator output latch mode
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_set_comp_latch(i2c_dev_t *dev, ads111x_comp_latch_t latch)
Set comparator output latch mode.
ADS1114 and ADS1115 only.
- Parameters:
dev – Device descriptor
latch – Comparator output latch mode
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_get_comp_queue(i2c_dev_t *dev, ads111x_comp_queue_t *queue)
Get comparator queue size.
Get number of the comparator conversions before pin ALERT/RDY assertion. ADS1114 and ADS1115 only.
- Parameters:
dev – Device descriptor
queue – [out] Number of the comparator conversions
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_set_comp_queue(i2c_dev_t *dev, ads111x_comp_queue_t queue)
Set comparator queue size.
Set number of the comparator conversions before pin ALERT/RDY assertion or disable comparator. ADS1114 and ADS1115 only.
- Parameters:
dev – Device descriptor
queue – Number of the comparator conversions
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_get_comp_low_thresh(i2c_dev_t *dev, int16_t *th)
Get the lower threshold value used by comparator.
- Parameters:
dev – Device descriptor
th – [out] Lower threshold value
- Returns:
ESP_OK
on success
-
esp_err_t ads111x_set_comp_low_thresh(i2c_dev_t *dev, int16_t th)
Set the lower threshold value used by comparator.
- Parameters:
dev – Device descriptor
th – Lower threshold value
- Returns:
ESP_OK
on success
Variables
-
const float ads111x_gain_values[]
Gain amplifier values.
-
ADS111X_ADDR_GND