sgm58031 - Driver for SGM58031 16-bit ADC¶
- group sgm58031
ESP-IDF driver for SGM58031 16-bit I2C ADC.
Copyright (c) 2023 Jose Manuel Perez jmpmscorp@hotmail.com
Defines
-
SGM58031_ADDR_GND¶
I2C device address with ADDR pin connected to ground.
-
SGM58031_ADDR_VCC¶
I2C device address with ADDR pin connected to VCC.
-
SGM58031_ADDR_SDA¶
I2C device address with ADDR pin connected to SDA.
-
SGM58031_ADDR_SCL¶
I2C device address with ADDR pin connected to SCL.
-
SGM58031_MAX_VALUE¶
Maximum ADC value.
Enums
-
enum sgm58031_gain_t¶
Gain amplifier.
Values:
-
enumerator SGM58031_GAIN_6V144¶
+-6.144V
-
enumerator SGM58031_GAIN_4V096¶
+-4.096V
-
enumerator SGM58031_GAIN_2V048¶
+-2.048V (default)
-
enumerator SGM58031_GAIN_1V024¶
+-1.024V
-
enumerator SGM58031_GAIN_0V512¶
+-0.512V
-
enumerator SGM58031_GAIN_0V256¶
+-0.256V
-
enumerator SGM58031_GAIN_0V256_2¶
+-0.256V (same as ADS111X_GAIN_0V256)
-
enumerator SGM58031_GAIN_0V256_3¶
+-0.256V (same as ADS111X_GAIN_0V256)
-
enumerator SGM58031_GAIN_6V144¶
-
enum sgm58031_mux_t¶
Input multiplexer configuration.
Values:
-
enumerator SGM58031_MUX_AIN0_AIN1¶
positive = AIN0, negative = AIN1 (default)
-
enumerator SGM58031_MUX_AIN0_AIN3¶
positive = AIN0, negative = AIN3
-
enumerator SGM58031_MUX_AIN1_AIN3¶
positive = AIN1, negative = AIN3
-
enumerator SGM58031_MUX_AIN2_AIN3¶
positive = AIN2, negative = AIN3
-
enumerator SGM58031_MUX_AIN0_GND¶
positive = AIN0, negative = GND
-
enumerator SGM58031_MUX_AIN1_GND¶
positive = AIN1, negative = GND
-
enumerator SGM58031_MUX_AIN2_GND¶
positive = AIN2, negative = GND
-
enumerator SGM58031_MUX_AIN3_GND¶
positive = AIN3, negative = GND
-
enumerator SGM58031_MUX_AIN0_AIN1¶
-
enum sgm58031_data_rate_t¶
Data rate.
Values:
-
enumerator SGM58031_DATA_RATE_6_25¶
6.25 samples per second (DR_SEL = 0)
-
enumerator SGM58031_DATA_RATE_12_5¶
12.5 samples per second (DR_SEL = 0)
-
enumerator SGM58031_DATA_RATE_25¶
25 samples per second (DR_SEL = 0)
-
enumerator SGM58031_DATA_RATE_50¶
50 samples per second (DR_SEL = 0)
-
enumerator SGM58031_DATA_RATE_100¶
100 samples per second (DR_SEL = 0) (default)
-
enumerator SGM58031_DATA_RATE_200¶
200 samples per second (DR_SEL = 0)
-
enumerator SGM58031_DATA_RATE_400¶
400 samples per second (DR_SEL = 0)
-
enumerator SGM58031_DATA_RATE_800¶
800 samples per second (DR_SEL = 0)
-
enumerator SGM58031_DATA_RATE_7_5¶
7.5 samples per second (DR_SEL = 1)
-
enumerator SGM58031_DATA_RATE_15¶
15 samples per second (DR_SEL = 1)
-
enumerator SGM58031_DATA_RATE_30¶
30 samples per second (DR_SEL = 1)
-
enumerator SGM58031_DATA_RATE_60¶
60 samples per second (DR_SEL = 1)
-
enumerator SGM58031_DATA_RATE_120¶
120 samples per second (DR_SEL = 1)
-
enumerator SGM58031_DATA_RATE_240¶
240 samples per second (DR_SEL = 1)
-
enumerator SGM58031_DATA_RATE_480¶
480 samples per second (DR_SEL = 1)
-
enumerator SGM58031_DATA_RATE_960¶
960 samples per second (DR_SEL = 1)
-
enumerator SGM58031_DATA_RATE_6_25¶
-
enum sgm58031_conv_mode_t¶
Device operating mode.
Values:
-
enumerator SGM58031_CONV_MODE_CONTINUOUS¶
Continuous conversion mode.
-
enumerator SGM58031_CONV_MODE_SINGLE_SHOT¶
Power-down single-shot mode (default)
-
enumerator SGM58031_CONV_MODE_CONTINUOUS¶
-
enum sgm58031_comp_mode_t¶
Comparator mode.
Values:
-
enumerator SGM58031_COMP_MODE_NORMAL¶
Traditional comparator with hysteresis (default)
-
enumerator SGM58031_COMP_MODE_WINDOW¶
Window comparator.
-
enumerator SGM58031_COMP_MODE_NORMAL¶
-
enum sgm58031_comp_polarity_t¶
Comparator polarity.
Values:
-
enumerator SGM58031_COMP_POLARITY_LOW¶
Active low (default)
-
enumerator SGM58031_COMP_POLARITY_HIGH¶
Active high.
-
enumerator SGM58031_COMP_POLARITY_LOW¶
-
enum sgm58031_comp_latch_t¶
Comparator latch.
Values:
-
enumerator SGM58031_COMP_LATCH_DISABLED¶
Non-latching comparator (default)
-
enumerator SGM58031_COMP_LATCH_ENABLED¶
Latching comparator.
-
enumerator SGM58031_COMP_LATCH_DISABLED¶
-
enum sgm58031_comp_queue_t¶
Comparator queue.
Values:
-
enumerator SGM58031_COMP_QUEUE_1¶
Assert ALERT/RDY pin after one conversion.
-
enumerator SGM58031_COMP_QUEUE_2¶
Assert ALERT/RDY pin after two conversions.
-
enumerator SGM58031_COMP_QUEUE_4¶
Assert ALERT/RDY pin after four conversions.
-
enumerator SGM58031_COMP_QUEUE_DISABLED¶
Disable comparator (default)
-
enumerator SGM58031_COMP_QUEUE_1¶
Functions
-
esp_err_t sgm58031_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 – [in] Device descriptor
addr – [in] Device address
port – [in] I2C port number
sda_gpio – [in] GPIO pin for SDA
scl_gpio – [in] GPIO pin for SCL
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_free_desc(i2c_dev_t *dev)¶
Free device descriptor.
- Parameters
dev – [in] Device descriptor
- Returns
ESP_OK
on success
-
esp_err_t sgm58031_is_busy(i2c_dev_t *dev, bool *busy)¶
Get device operational status.
- Parameters
dev – [in] Device descriptor
busy – [out] True when device performing conversion
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_start_conversion(i2c_dev_t *dev)¶
Begin a single conversion.
Only in single-shot mode.
- Parameters
dev – [in] Device descriptor
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_value(i2c_dev_t *dev, int16_t *value)¶
Read last conversion result.
- Parameters
dev – [in] Device descriptor
value – [out] Last conversion result
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_gain(i2c_dev_t *dev, sgm58031_gain_t *gain)¶
Read the programmable gain amplifier configuration.
Use sgm58031_gain_values[] for real voltage.
- Parameters
dev – [in] Device descriptor
gain – [out] Gain value
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev or gain are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_gain(i2c_dev_t *dev, sgm58031_gain_t gain)¶
Configure the programmable gain amplifier.
- Parameters
dev – [in] Device descriptor
gain – [in] Gain value
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_input_mux(i2c_dev_t *dev, sgm58031_mux_t *mux)¶
Read the input multiplexer configuration.
- Parameters
dev – [in] Device descriptor
mux – [out] Input multiplexer configuration
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev or mux are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_input_mux(i2c_dev_t *dev, sgm58031_mux_t mux)¶
Configure the input multiplexer configuration.
- Parameters
dev – [in] Device descriptor
mux – [in] Input multiplexer configuration
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_conv_mode(i2c_dev_t *dev, sgm58031_conv_mode_t *mode)¶
Read the device operating conversion mode.
- Parameters
dev – [in] Device descriptor
mode – [out] Device operating mode
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev or mode are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_conv_mode(i2c_dev_t *dev, sgm58031_conv_mode_t mode)¶
Set the device operating mode.
- Parameters
dev – [in] Device descriptor
mode – [in] Device operating mode
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_data_rate(i2c_dev_t *dev, sgm58031_data_rate_t *rate)¶
Read the data rate.
- Parameters
dev – [in] Device descriptor
rate – [out] Data rate
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev or rate are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_data_rate(i2c_dev_t *dev, sgm58031_data_rate_t rate)¶
Configure the data rate.
- Parameters
dev – [in] Device descriptor
rate – [in] Data rate
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_comp_mode(i2c_dev_t *dev, sgm58031_comp_mode_t *mode)¶
Get comparator mode.
- Parameters
dev – [in] Device descriptor
mode – [out] Comparator mode
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev or mode are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_comp_mode(i2c_dev_t *dev, sgm58031_comp_mode_t mode)¶
Set comparator mode.
- Parameters
dev – Device descriptor
mode – Comparator mode
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_comp_polarity(i2c_dev_t *dev, sgm58031_comp_polarity_t *polarity)¶
Get polarity of the comparator output pin ALERT/RDY.
- Parameters
dev – [in] Device descriptor
polarity – [out] Comparator output pin polarity
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev or polarity are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_comp_polarity(i2c_dev_t *dev, sgm58031_comp_polarity_t polarity)¶
Set polarity of the comparator output pin ALERT/RDY.
- Parameters
dev – [in] Device descriptor
polarity – [in] Comparator output pin polarity
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_comp_latch(i2c_dev_t *dev, sgm58031_comp_latch_t *latch)¶
Get comparator output latch mode.
- Parameters
dev – [in] Device descriptor
latch – [out] Comparator output latch mode
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev or latch are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_comp_latch(i2c_dev_t *dev, sgm58031_comp_latch_t latch)¶
Set comparator output latch mode.
- Parameters
dev – [in] Device descriptor
latch – [in] Comparator output latch mode
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_comp_queue(i2c_dev_t *dev, sgm58031_comp_queue_t *queue)¶
Get comparator queue size.
Get number of the comparator conversions before pin ALERT/RDY assertion.
- Parameters
dev – [in] Device descriptor
queue – [out] Number of the comparator conversions
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev or queue are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_comp_queue(i2c_dev_t *dev, sgm58031_comp_queue_t queue)¶
Set comparator queue size.
Set number of the comparator conversions before pin ALERT/RDY assertion or disable comparator.
- Parameters
dev – [in] Device descriptor
queue – [in] Number of the comparator conversions
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_comp_low_thresh(i2c_dev_t *dev, int16_t *th)¶
Get the lower threshold value used by comparator.
- Parameters
dev – [in] Device descriptor
th – [out] Lower threshold value
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev or th are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_comp_low_thresh(i2c_dev_t *dev, int16_t th)¶
Set the lower threshold value used by comparator.
- Parameters
dev – [in] Device descriptor
th – [in] Lower threshold value
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_comp_high_thresh(i2c_dev_t *dev, int16_t *th)¶
Get the upper threshold value used by comparator.
- Parameters
dev – [in] Device descriptor
th – [out] Upper threshold value
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev or th are NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_comp_high_thresh(i2c_dev_t *dev, int16_t th)¶
Set the upper threshold value used by comparator.
- Parameters
dev – [in] Device descriptor
th – [in] Upper threshold value
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_ain3_external_reference(i2c_dev_t *dev, bool enable)¶
Enable/disable ain3 as external reference.
- Parameters
dev – [in] Device descriptor
enable – [in] True to enable. False to disable
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_ain3_external_reference(i2c_dev_t *dev, bool *enable)¶
Get ain3 as external reference enable/disable bit.
- Parameters
dev – [in] Device descriptor
enable – [out] True, enable. False, disable
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_source_pair(i2c_dev_t *dev, bool enable)¶
Enable/disable source pair of 2uA to selected pair of AINx.
- Parameters
dev – [in] Device descriptor
enable – [in] True to enable. False to disable
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_source_pair(i2c_dev_t *dev, bool *enable)¶
Get burnout enable/disable bit.
- Parameters
dev – [in] Device descriptor
enable – [out] True, enable. False, disable
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_set_bus_leakage_circuit(i2c_dev_t *dev, bool enable)¶
Enable/disable I2C bus leakage blocking circuit.
- Parameters
dev – [in] Device descriptor
enable – [in] True to enable. False to disable
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_bus_leakage_circuit(i2c_dev_t *dev, bool *enable)¶
Get I2C bus leakage blocking circuit enable/disable bit.
- Parameters
dev – [in] Device descriptor
enable – [out] True, enable. False, disable
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev is NULLESP_FAIL
otherwise
-
esp_err_t sgm58031_get_chip_id(i2c_dev_t *dev, uint8_t *id, uint8_t *version)¶
Get chip id values.
- Parameters
dev – [in] Device descriptor
id – [out] ID value
version – [out] Version value
- Returns
ESP_OK
on successESP_INVALID_ARG
if dev, id or version are NULLESP_FAIL
otherwise
Variables
-
const float sgm58031_gain_values[]¶
Gain amplifier values.
-
SGM58031_ADDR_GND¶