# esp-idf-lib/ads130e08
[](https://github.com/esp-idf-lib/ads130e08/actions/workflows/build.yml)
[](https://github.com/esp-idf-lib/ads130e08/actions/workflows/build-docs.yml)
[](https://github.com/esp-idf-lib/ads130e08/actions/workflows/validate-component.yml)
Driver for the Texas Instruments ADS130E08 eight-channel, 16-bit,
simultaneous-sampling delta-sigma ADC.
* [Documentation](https://esp-idf-lib.github.io/ads130e08/)
* [Repository](https://github.com/esp-idf-lib/ads130e08)
* [Issues](https://github.com/esp-idf-lib/ads130e08/issues)
* [Discussions and questions](https://github.com/esp-idf-lib/core/discussions)
* [Component page at the ESP Component Registry](https://components.espressif.com/components/esp-idf-lib/ads130e08)
The ADS130E08 is the 16 kSPS member of the ADS131 family: eight differential
inputs sampled at the same instant, each with its own 16-bit converter and a
programmable gain stage. It is meant for three-phase power meters, energy
monitoring and multi-channel data acquisition, where all channels must be
sampled together.
## Features
- Eight differential channels, 16-bit two's complement, sampled simultaneously.
- Per-channel PGA gain of 1, 2 or 8.
- Per-channel input multiplexer: normal input, shorted input for offset and
noise measurement, `MVDD` supply measurement, internal temperature sensor,
internal test signal.
- Internal reference, 2.4 V by default, 4 V optional (analog supply must be
5 V for that), with a switchable reference buffer.
- Internal op amp that can drive the negative inputs from `(AVDD + AVSS) / 2`.
- Four general-purpose pins, each configurable as input or output.
- Fault detection comparators with eight threshold pairs and `FAULT_STATP` /
`FAULT_STATN` readback.
- Clock output to synchronise several devices, and a multi-device mode.
- Commands for continuous conversion (`RDATAC`), single reads (`RDATA`),
register access (`RREG`/`WREG`) and the usual power-down sequence
(`STANDBY`, `WAKEUP`, `RESET`).
- SPI mode 1, up to 4 MHz on this driver, one device per chip select.
## Hardware
| Signal | Direction | Notes |
| --- | --- | --- |
| `SCLK` | ESP32 → ADC | SPI clock, mode 1 |
| `MOSI` (`DIN`) | ESP32 → ADC | commands and register writes |
| `MISO` (`DOUT`) | ADC → ESP32 | data and register reads |
| `CS` | ESP32 → ADC | chip select, driven by the SPI driver |
| `DRDY` | ADC → ESP32 | active low, a new sample is ready |
The analog supply (`AVDD`/`AVSS`), the digital supply (`DVDD`) and the
reference decoupling are described in the datasheet; this component only
drives the digital side. `RESET` may be tied high and reset through the
`RESET` command, which is what the example does.
The example uses these pins by default and lets you change them in
`idf.py menuconfig`:
| Signal | ESP32 | ESP32-S2/S3 | ESP32-C2/C3/C5/C6/C61, H2, P4 |
| --- | --- | --- | --- |
| `MOSI` | 23 | 11 | 4 |
| `MISO` | 19 | 13 | 5 |
| `SCLK` | 18 | 12 | 6 |
| `CS` | 6 | 10 | 7 |
| `DRDY` | 26 | 2 | 8 |
## Usage
```c
#include <ads130e08.h>
spi_bus_config_t bus_cfg = {
.mosi_io_num = 23,
.miso_io_num = 19,
.sclk_io_num = 18,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
};
ESP_ERROR_CHECK(spi_bus_initialize(SPI2_HOST, &bus_cfg, SPI_DMA_CH_AUTO));
ads130e08_t adc;
ESP_ERROR_CHECK(ads130e08_init_desc(&adc, SPI2_HOST, 6));
ads130e08_dev_config_t dev_cfg = {
.clk_en = ADS130E08_CLK_OUT_DISABLED,
.int_test = ADS130E08_INT_TEST_EXTERNAL,
.test_amp = ADS130E08_TEST_AMP_CALIB_1X,
.test_freq = ADS130E08_TEST_FREQ_EXP_21,
.pd_refbuf = ADS130E08_INTERNAL_REF_BUFFER_ENABLED,
.vref_4v = ADS130E08_REF_VOLTAGE_2_4V,
.opamp_ref = ADS130E08_NON_INVERTING_CONNECT_OPAMP,
.pd_opamp = ADS130E08_OPAMP_DISABLED,
};
/* Stop continuous conversion before touching the registers. */
ESP_ERROR_CHECK(ads130e08_send_system_cmd(&adc, ADS130E08_CMD_STOP));
ESP_ERROR_CHECK(ads130e08_send_system_cmd(&adc, ADS130E08_CMD_RESET));
ESP_ERROR_CHECK(ads130e08_send_data_read_cmd(&adc, ADS130E08_CMD_SDATAC));
ESP_ERROR_CHECK(ads130e08_set_device_config(&adc, dev_cfg));
ads130e08_channel_config_t ch_cfg = {
.enable = ADS130E08_NORMAL_OPERATION,
.pga_gain = ADS130E08_PGA_1,
.mode = ADS130E08_NORMAL_INPUT,
};
ESP_ERROR_CHECK(ads130e08_set_channel_config(&adc, ADS130E08_CHANNEL_1, ch_cfg));
ESP_ERROR_CHECK(ads130e08_send_system_cmd(&adc, ADS130E08_CMD_START));
/* Wait for DRDY (active low) and read all eight channels at once. */
ads130e08_raw_data_t sample;
ESP_ERROR_CHECK(ads130e08_get_rdata(&adc, &sample));
float volts;
ESP_ERROR_CHECK(ads130e08_convert_raw_to_voltage(sample.channels_raw[0],
ADS130E08_PGA_1, &volts));
```
`ads130e08_init_desc()` only adds the device to an already initialised SPI bus;
the bus itself is the application's business. `ads130e08_free_desc()` removes
the device again.
A complete working example is in `examples/default`: it reads samples on the
`DRDY` interrupt, prints the fault status, the GPIO levels and the raw values
of all eight channels.
## API
| Function | Purpose |
| --- | --- |
| `ads130e08_init_desc()` | add the ADC to an initialised SPI bus |
| `ads130e08_free_desc()` | remove the ADC from the bus |
| `ads130e08_send_system_cmd()` | `WAKEUP`, `STANDBY`, `RESET`, `START`, `STOP` |
| `ads130e08_send_data_read_cmd()` | `RDATAC`, `SDATAC`, `RDATA` |
| `ads130e08_get_device_id()` | read the device ID register |
| `ads130e08_set_device_config()` / `ads130e08_get_device_config()` | `CONFIG1`–`CONFIG3` as one structure |
| `ads130e08_set_channel_config()` / `ads130e08_get_channel_config()` | gain, power state and input mux of one channel |
| `ads130e08_get_rdata()` | fault status, GPIO levels and eight raw samples in one frame |
| `ads130e08_convert_raw_to_voltage()` | raw value and gain to volts |
| `ads130e08_set_fault_detect_control()` / `ads130e08_get_fault_detect_control()` | comparator thresholds |
| `ads130e08_set_gpio_pin_mode()` / `ads130e08_get_gpio_pin_mode()` | GPIO 1…4 as input or output |
| `ads130e08_set_gpio_pin_level()` / `ads130e08_get_gpio_pin_level()` | level of a GPIO configured as output or input |
| `ads130e08_detect_fault_auto()` | run one fault detection cycle and read both status bytes |
## Limitations
- `ads130e08_convert_raw_to_voltage()` assumes the 2.4 V reference. With the
4 V reference the divisor must be changed or the value scaled by hand; the
function derives volts as `2.4 / 32768 * raw / gain`.
- The gain argument is a plain number (`1`, `2`, `8`), not the
`ads130e08_pga_gain_t` value: the enum holds the register field.
- The driver does not serialise access to the descriptor. A descriptor used
from one task, as in the example, needs no locking; several tasks must
provide their own mutex.
- The status word is decoded but its `1100` preamble is not verified, so a
misaligned frame is not detected; the sample values are taken from the frame
as-is.
- The example waits for `DRDY` through a GPIO interrupt; polling `DRDY` is
possible but loses samples when the loop is slower than the data rate.
## Installation
```sh
idf.py add-dependency esp-idf-lib/ads130e08
```
## Support
For questions and discussions about the component, please use
[Discussions](https://github.com/esp-idf-lib/core/discussions)
at [esp-idf-lib/core](https://github.com/esp-idf-lib/core).
## Contributing
Please read [CONTRIBUTING.md](https://github.com/esp-idf-lib/core/blob/main/CONTRIBUTING.md)
at [esp-idf-lib/core](https://github.com/esp-idf-lib/core).
26baf93f49c38f76e52dd05787a9f8958a7b6539
idf.py add-dependency "esp-idf-lib/ads130e08^1.0.11"