ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
esphome::ads131m0x::ADS131M0x Class Referencefinal

TI ADS131M02/04/08 simultaneous-sampling 24-bit delta-sigma ADC (https://www.ti.com/lit/ds/symlink/ads131m08.pdf). More...

#include <ads131m0x.h>

Inheritance diagram for esphome::ads131m0x::ADS131M0x:
esphome::Component esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_TRAILING, spi::DATA_RATE_8MHZ > esphome::spi::SPIClient

Public Member Functions

void setup () override
 
void dump_config () override
 
void set_num_channels (uint8_t num_channels)
 
void set_drdy_pin (InternalGPIOPin *pin)
 
void set_reset_pin (InternalGPIOPin *pin)
 
void set_power_mode (ADS131M0xPowerMode power_mode)
 
void set_osr_code (uint8_t code)
 
void set_sample_rate (float sample_rate)
 
void set_window_ms (uint32_t window_ms)
 
void set_gain (uint8_t channel, uint8_t gain_code)
 
Snapshot get_snapshot ()
 Copy of the latest completed window; sequence is 0 until the first window after (re)configuration.
 
bool is_healthy () const
 True while the device is configured and delivers samples at the expected rate.
 
uint32_t get_window_ms () const
 
float get_full_scale (uint8_t channel) const
 Input full scale of a channel in volts (the input range is +/- this value).
 
- Public Member Functions inherited from esphome::Component
virtual void loop ()
 This method will be called repeatedly.
 
virtual float get_setup_priority () const
 priority of setup().
 
float get_actual_setup_priority () const
 
void set_setup_priority (float priority)
 
void call ()
 
virtual void on_shutdown ()
 
virtual void on_safe_shutdown ()
 
virtual bool teardown ()
 Called during teardown to allow component to gracefully finish operations.
 
virtual void on_powerdown ()
 Called last before a reboot or deep sleep to power down hardware.
 
uint8_t get_component_state () const
 
void reset_to_construction_state ()
 Reset this component back to the construction state to allow setup to run again.
 
bool is_in_loop_state () const
 Check if this component has completed setup and is in the loop state.
 
bool is_idle () const
 Check if this component is idle.
 
void mark_failed ()
 Mark this component as failed.
 
void mark_failed (const LogString *message)
 
bool ESPHOME_ALWAYS_INLINE setup_check (bool ok)
 Marks the component failed with message (default "Communication failed") unless ok; returns ok.
 
bool ESPHOME_ALWAYS_INLINE setup_check (bool ok, const LogString *message)
 
void disable_loop ()
 Disable this component's loop.
 
void enable_loop ()
 Enable this component's loop.
 
void enable_loop_soon_any_context ()
 Thread and ISR-safe version of enable_loop() that can be called from any context.
 
bool is_failed () const
 
bool is_ready () const
 
virtual bool can_proceed ()
 
bool status_has_warning () const
 
bool status_has_error () const
 
void status_set_warning ()
 
void status_set_warning (const char *message)
 
void status_set_warning (const LogString *message)
 
bool status_comm_result (bool ok)
 Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
 
bool status_comm_result (bool ok, const LogString *message)
 
bool status_comm_check (bool ok)
 Sets the warning ("Communication failed") when not ok but never clears it; returns ok.
 
void status_set_error ()
 
void status_set_error (const LogString *message)
 
void status_clear_warning ()
 
void status_clear_error ()
 
 ESPDEPRECATED ("Use status_momentary_warning() without a name. Removed in 2027.5.0", "2026.11.0") void status_momentary_warning(const char *name
 
void status_momentary_warning (uint32_t length=5000)
 Set warning status flag and clear it after length ms.
 
void status_momentary_warning (const LogString *message, uint32_t length=5000)
 
 ESPDEPRECATED ("Use status_momentary_error() without a name. Removed in 2027.5.0", "2026.11.0") void status_momentary_error(const char *name
 
void status_momentary_error (uint32_t length=5000)
 Set error status flag and clear it after length ms.
 
void status_momentary_error (const LogString *message, uint32_t length=5000)
 
bool has_overridden_loop () const
 
const LogString * get_component_log_str () const ESPHOME_ALWAYS_INLINE
 Get the integration where this component was declared as a LogString for logging.
 
bool should_warn_of_blocking (uint32_t blocking_time, uint32_t &threshold_ms_out)
 
- Public Member Functions inherited from esphome::spi::SPIDevice< spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_TRAILING, spi::DATA_RATE_8MHZ >
 SPIDevice ()
 
 SPIDevice (SPIComponent *parent, GPIOPin *cs_pin)
 
void spi_setup () override
 
void spi_teardown () override
 
void set_spi_parent (SPIComponent *parent)
 
void set_cs_pin (GPIOPin *cs)
 
void set_data_rate (uint32_t data_rate)
 
void set_bit_order (SPIBitOrder order)
 
void set_mode (SPIMode mode)
 
uint8_t read_byte ()
 
void read_array (uint8_t *data, size_t length)
 
void write (uint16_t data, size_t num_bits)
 Write a single data item, up to 32 bits.
 
void write_cmd_addr_data (size_t cmd_bits, uint32_t cmd, size_t addr_bits, uint32_t address, const uint8_t *data, size_t length, uint8_t bus_width=1)
 
void write_byte (uint8_t data)
 
void transfer_array (uint8_t *data, size_t length)
 Write the array data, replace with received data.
 
void transfer_array (std::array< uint8_t, N > &data)
 
uint8_t transfer_byte (uint8_t data)
 
void write_byte16 (uint16_t data)
 Write 16 bit data.
 
void write_array16 (const uint16_t *data, size_t length)
 Write an array of data as 16 bit values, byte-swapping if required.
 
void enable ()
 
void disable ()
 
void write_array (const uint8_t *data, size_t length)
 
void write_array (const std::array< uint8_t, N > &data)
 
void write_array (const std::vector< uint8_t > &data)
 
- Public Member Functions inherited from esphome::spi::SPIClient
 SPIClient (SPIBitOrder bit_order, SPIMode mode, uint32_t data_rate)
 
bool spi_is_ready ()
 
void set_release_device (bool release)
 
void set_write_only (bool write_only)
 
void set_psram_dma (bool enable)
 

Protected Member Functions

void task_loop_ ()
 
void check_health_ ()
 
void check_rate_ (uint32_t elapsed_ms, uint32_t frames)
 Averages the sample rate over several health checks and warns when conversions are being lost.
 
const LogString * configure_ ()
 Resets (if a reset pin is set) and configures the device. Returns nullptr on success, else the reason.
 
bool transfer_frame_ (uint16_t command, uint16_t data, uint16_t *response, int32_t *samples)
 Clocks one full frame. Returns false on an output CRC mismatch. response receives the first word.
 
bool read_register_ (uint8_t address, uint16_t *value)
 
bool write_register_ (uint8_t address, uint16_t value)
 
size_t frame_bytes_ () const
 
void drain_fifo_ ()
 Reads both FIFO slots back to back, as the datasheet requires after a gap in reading.
 
void invalidate_snapshot_ ()
 Marks the snapshot as invalid (sequence 0) until a full window has been sampled again.
 
- Protected Member Functions inherited from esphome::Component
friend void::setup ()
 
friend void::original_setup ()
 
void set_component_source_ (uint8_t index)
 Set where this component was loaded from for some debug messages.
 
virtual void call_setup ()
 
void call_dump_config_ ()
 
void enable_loop_slow_path_ ()
 
void set_component_state_ (uint8_t state)
 Helper to set component state (clears state bits and sets new state)
 
bool set_status_flag_ (uint8_t flag)
 Helper to set a status LED flag on both this component and the app.
 
bool set_error_flag_ (const LogString *message)
 Set the error flag and log it; true when it was not set before.
 
void set_interval (const char *name, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a const char* name.
 
void set_interval (uint32_t id, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a numeric ID (zero heap allocation).
 
void set_interval (InternalSchedulerID id, uint32_t interval, std::function< void()> &&f)
 
void set_interval (uint32_t interval, std::function< void()> &&f)
 
bool cancel_interval (const char *name)
 Cancel an interval function.
 
bool cancel_interval (uint32_t id)
 
bool cancel_interval (InternalSchedulerID id)
 
void set_timeout (const char *name, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a const char* name.
 
void set_timeout (uint32_t id, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a numeric ID (zero heap allocation).
 
void set_timeout (InternalSchedulerID id, uint32_t timeout, std::function< void()> &&f)
 
void set_timeout (uint32_t timeout, std::function< void()> &&f)
 
bool cancel_timeout (const char *name)
 Cancel a timeout function.
 
bool cancel_timeout (uint32_t id)
 
bool cancel_timeout (InternalSchedulerID id)
 
void defer (const char *name, std::function< void()> &&f)
 Defer a callback to the next loop() call with a const char* name.
 
void defer (std::function< void()> &&f)
 Defer a callback to the next loop() call.
 
void defer (uint32_t id, std::function< void()> &&f)
 Defer a callback with a numeric ID (zero heap allocation)
 
bool cancel_defer (const char *name)
 Cancel a defer callback using the specified name, name must not be empty.
 
bool cancel_defer (uint32_t id)
 
void status_clear_warning_slow_path_ ()
 
void status_comm_check_slow_path_ ()
 
void status_clear_error_slow_path_ ()
 

Static Protected Member Functions

static void task_entry (void *arg)
 
static void drdy_isr (ADS131M0x *self)
 

Protected Attributes

InternalGPIOPin * drdy_pin_ {nullptr}
 
InternalGPIOPin * reset_pin_ {nullptr}
 
uint8_t num_channels_ {MAX_CHANNELS}
 
ADS131M0xPowerMode power_mode_ {ADS131M0X_POWER_MODE_HIGH_RESOLUTION}
 
uint8_t osr_code_ {3}
 
float sample_rate_ {4000.0f}
 
uint32_t window_ms_ {100}
 
std::array< uint8_t, MAX_CHANNELS > gain_codes_ {}
 
StaticTask task_
 
portMUX_TYPE lock_ = portMUX_INITIALIZER_UNLOCKED
 
Snapshot snapshot_ {}
 
uint8_t * frame_buf_ {nullptr}
 DMA-capable, allocated once in setup()
 
size_t transfer_bytes_ {0}
 Frame length, padded where the DMA requires it.
 
uint32_t window_sequence_ {0}
 
std::atomic< uint8_t > healthy_ {0}
 
std::atomic< uint8_t > configured_ {0}
 
std::atomic< uint32_t > frames_ {0}
 
std::atomic< uint32_t > crc_errors_ {0}
 
std::atomic< uint32_t > device_resets_ {0}
 
uint32_t last_health_check_ {0}
 
uint32_t last_frames_ {0}
 
uint32_t last_crc_errors_ {0}
 
uint32_t last_device_resets_ {0}
 
uint32_t rate_start_frames_ {0}
 
uint32_t rate_elapsed_ms_ {0}
 
uint8_t rate_checks_ {0}
 
bool rate_degraded_ {false}
 
- Protected Attributes inherited from esphome::Component
uint8_t component_source_index_ {0}
 Index into component source PROGMEM lookup table (0 = not set)
 
uint8_t warn_if_blocking_over_ {WARN_IF_BLOCKING_OVER_CS}
 Warn threshold in centiseconds (max 2550ms)
 
uint8_t component_state_ {0x00}
 State of this component - each bit has a purpose: Bits 0-2: Component state (0x00=CONSTRUCTION, 0x01=SETUP, 0x02=LOOP, 0x03=FAILED, 0x04=LOOP_DONE) Bit 3: STATUS_LED_WARNING Bit 4: STATUS_LED_ERROR Bit 5: Has overridden loop() (set at registration time) Bits 6-7: Unused - reserved for future expansion.
 
volatile bool pending_enable_loop_ {false}
 ISR-safe flag for enable_loop_soon_any_context.
 
ComponentRuntimeStats runtime_stats_
 
- Protected Attributes inherited from esphome::spi::SPIClient
SPIBitOrder bit_order_ {BIT_ORDER_MSB_FIRST}
 
SPIMode mode_ {MODE0}
 
uint32_t data_rate_ {1000000}
 
SPIComponent * parent_ {nullptr}
 
GPIOPin * cs_ {nullptr}
 
bool release_device_ {false}
 
bool write_only_ {false}
 
bool psram_dma_ {false}
 
SPIDelegate * delegate_ {SPIDelegate::NULL_DELEGATE}
 

Additional Inherited Members

- Data Fields inherited from esphome::Component
uint32_t length = 5000)
 

Detailed Description

TI ADS131M02/04/08 simultaneous-sampling 24-bit delta-sigma ADC (https://www.ti.com/lit/ds/symlink/ads131m08.pdf).

A FreeRTOS task woken by DRDY reads every conversion, checks CRC and STATUS, reconfigures after a device reset, and publishes mean and AC RMS per window as a Snapshot.

Definition at line 38 of file ads131m0x.h.

Member Function Documentation

◆ check_health_()

void esphome::ads131m0x::ADS131M0x::check_health_ ( )
protected

Definition at line 145 of file ads131m0x.cpp.

◆ check_rate_()

void esphome::ads131m0x::ADS131M0x::check_rate_ ( uint32_t elapsed_ms,
uint32_t frames )
protected

Averages the sample rate over several health checks and warns when conversions are being lost.

Definition at line 185 of file ads131m0x.cpp.

◆ configure_()

const LogString * esphome::ads131m0x::ADS131M0x::configure_ ( )
protected

Resets (if a reset pin is set) and configures the device. Returns nullptr on success, else the reason.

Definition at line 290 of file ads131m0x.cpp.

◆ drain_fifo_()

void esphome::ads131m0x::ADS131M0x::drain_fifo_ ( )
protected

Reads both FIFO slots back to back, as the datasheet requires after a gap in reading.

Definition at line 254 of file ads131m0x.cpp.

◆ drdy_isr()

void IRAM_ATTR esphome::ads131m0x::ADS131M0x::drdy_isr ( ADS131M0x * self)
staticprotected

Definition at line 214 of file ads131m0x.cpp.

◆ dump_config()

void esphome::ads131m0x::ADS131M0x::dump_config ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 117 of file ads131m0x.cpp.

◆ frame_bytes_()

size_t esphome::ads131m0x::ADS131M0x::frame_bytes_ ( ) const
protected

Definition at line 222 of file ads131m0x.cpp.

◆ get_full_scale()

float esphome::ads131m0x::ADS131M0x::get_full_scale ( uint8_t channel) const

Input full scale of a channel in volts (the input range is +/- this value).

Definition at line 134 of file ads131m0x.cpp.

◆ get_snapshot()

Snapshot esphome::ads131m0x::ADS131M0x::get_snapshot ( )

Copy of the latest completed window; sequence is 0 until the first window after (re)configuration.

Safe to call from any task.

Definition at line 138 of file ads131m0x.cpp.

◆ get_window_ms()

uint32_t esphome::ads131m0x::ADS131M0x::get_window_ms ( ) const
inline

Definition at line 59 of file ads131m0x.h.

◆ invalidate_snapshot_()

void esphome::ads131m0x::ADS131M0x::invalidate_snapshot_ ( )
protected

Marks the snapshot as invalid (sequence 0) until a full window has been sampled again.

Definition at line 260 of file ads131m0x.cpp.

◆ is_healthy()

bool esphome::ads131m0x::ADS131M0x::is_healthy ( ) const
inline

True while the device is configured and delivers samples at the expected rate.

Definition at line 58 of file ads131m0x.h.

◆ read_register_()

bool esphome::ads131m0x::ADS131M0x::read_register_ ( uint8_t address,
uint16_t * value )
protected

Definition at line 266 of file ads131m0x.cpp.

◆ set_drdy_pin()

void esphome::ads131m0x::ADS131M0x::set_drdy_pin ( InternalGPIOPin * pin)
inline

Definition at line 46 of file ads131m0x.h.

◆ set_gain()

void esphome::ads131m0x::ADS131M0x::set_gain ( uint8_t channel,
uint8_t gain_code )
inline

Definition at line 52 of file ads131m0x.h.

◆ set_num_channels()

void esphome::ads131m0x::ADS131M0x::set_num_channels ( uint8_t num_channels)
inline

Definition at line 45 of file ads131m0x.h.

◆ set_osr_code()

void esphome::ads131m0x::ADS131M0x::set_osr_code ( uint8_t code)
inline

Definition at line 49 of file ads131m0x.h.

◆ set_power_mode()

void esphome::ads131m0x::ADS131M0x::set_power_mode ( ADS131M0xPowerMode power_mode)
inline

Definition at line 48 of file ads131m0x.h.

◆ set_reset_pin()

void esphome::ads131m0x::ADS131M0x::set_reset_pin ( InternalGPIOPin * pin)
inline

Definition at line 47 of file ads131m0x.h.

◆ set_sample_rate()

void esphome::ads131m0x::ADS131M0x::set_sample_rate ( float sample_rate)
inline

Definition at line 50 of file ads131m0x.h.

◆ set_window_ms()

void esphome::ads131m0x::ADS131M0x::set_window_ms ( uint32_t window_ms)
inline

Definition at line 51 of file ads131m0x.h.

◆ setup()

void esphome::ads131m0x::ADS131M0x::setup ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 89 of file ads131m0x.cpp.

◆ task_entry()

void esphome::ads131m0x::ADS131M0x::task_entry ( void * arg)
staticprotected

Definition at line 220 of file ads131m0x.cpp.

◆ task_loop_()

void esphome::ads131m0x::ADS131M0x::task_loop_ ( )
protected

Definition at line 332 of file ads131m0x.cpp.

◆ transfer_frame_()

bool esphome::ads131m0x::ADS131M0x::transfer_frame_ ( uint16_t command,
uint16_t data,
uint16_t * response,
int32_t * samples )
protected

Clocks one full frame. Returns false on an output CRC mismatch. response receives the first word.

Definition at line 224 of file ads131m0x.cpp.

◆ write_register_()

bool esphome::ads131m0x::ADS131M0x::write_register_ ( uint8_t address,
uint16_t value )
protected

Definition at line 272 of file ads131m0x.cpp.

Field Documentation

◆ configured_

std::atomic<uint8_t> esphome::ads131m0x::ADS131M0x::configured_ {0}
protected

Definition at line 103 of file ads131m0x.h.

◆ crc_errors_

std::atomic<uint32_t> esphome::ads131m0x::ADS131M0x::crc_errors_ {0}
protected

Definition at line 105 of file ads131m0x.h.

◆ device_resets_

std::atomic<uint32_t> esphome::ads131m0x::ADS131M0x::device_resets_ {0}
protected

Definition at line 106 of file ads131m0x.h.

◆ drdy_pin_

InternalGPIOPin* esphome::ads131m0x::ADS131M0x::drdy_pin_ {nullptr}
protected

Definition at line 83 of file ads131m0x.h.

◆ frame_buf_

uint8_t* esphome::ads131m0x::ADS131M0x::frame_buf_ {nullptr}
protected

DMA-capable, allocated once in setup()

Definition at line 95 of file ads131m0x.h.

◆ frames_

std::atomic<uint32_t> esphome::ads131m0x::ADS131M0x::frames_ {0}
protected

Definition at line 104 of file ads131m0x.h.

◆ gain_codes_

std::array<uint8_t, MAX_CHANNELS> esphome::ads131m0x::ADS131M0x::gain_codes_ {}
protected

Definition at line 90 of file ads131m0x.h.

◆ healthy_

std::atomic<uint8_t> esphome::ads131m0x::ADS131M0x::healthy_ {0}
protected

Definition at line 102 of file ads131m0x.h.

◆ last_crc_errors_

uint32_t esphome::ads131m0x::ADS131M0x::last_crc_errors_ {0}
protected

Definition at line 111 of file ads131m0x.h.

◆ last_device_resets_

uint32_t esphome::ads131m0x::ADS131M0x::last_device_resets_ {0}
protected

Definition at line 112 of file ads131m0x.h.

◆ last_frames_

uint32_t esphome::ads131m0x::ADS131M0x::last_frames_ {0}
protected

Definition at line 110 of file ads131m0x.h.

◆ last_health_check_

uint32_t esphome::ads131m0x::ADS131M0x::last_health_check_ {0}
protected

Definition at line 109 of file ads131m0x.h.

◆ lock_

portMUX_TYPE esphome::ads131m0x::ADS131M0x::lock_ = portMUX_INITIALIZER_UNLOCKED
protected

Definition at line 93 of file ads131m0x.h.

◆ num_channels_

uint8_t esphome::ads131m0x::ADS131M0x::num_channels_ {MAX_CHANNELS}
protected

Definition at line 85 of file ads131m0x.h.

◆ osr_code_

uint8_t esphome::ads131m0x::ADS131M0x::osr_code_ {3}
protected

Definition at line 87 of file ads131m0x.h.

◆ power_mode_

ADS131M0xPowerMode esphome::ads131m0x::ADS131M0x::power_mode_ {ADS131M0X_POWER_MODE_HIGH_RESOLUTION}
protected

Definition at line 86 of file ads131m0x.h.

◆ rate_checks_

uint8_t esphome::ads131m0x::ADS131M0x::rate_checks_ {0}
protected

Definition at line 115 of file ads131m0x.h.

◆ rate_degraded_

bool esphome::ads131m0x::ADS131M0x::rate_degraded_ {false}
protected

Definition at line 116 of file ads131m0x.h.

◆ rate_elapsed_ms_

uint32_t esphome::ads131m0x::ADS131M0x::rate_elapsed_ms_ {0}
protected

Definition at line 114 of file ads131m0x.h.

◆ rate_start_frames_

uint32_t esphome::ads131m0x::ADS131M0x::rate_start_frames_ {0}
protected

Definition at line 113 of file ads131m0x.h.

◆ reset_pin_

InternalGPIOPin* esphome::ads131m0x::ADS131M0x::reset_pin_ {nullptr}
protected

Definition at line 84 of file ads131m0x.h.

◆ sample_rate_

float esphome::ads131m0x::ADS131M0x::sample_rate_ {4000.0f}
protected

Definition at line 88 of file ads131m0x.h.

◆ snapshot_

Snapshot esphome::ads131m0x::ADS131M0x::snapshot_ {}
protected

Definition at line 94 of file ads131m0x.h.

◆ task_

StaticTask esphome::ads131m0x::ADS131M0x::task_
protected

Definition at line 92 of file ads131m0x.h.

◆ transfer_bytes_

size_t esphome::ads131m0x::ADS131M0x::transfer_bytes_ {0}
protected

Frame length, padded where the DMA requires it.

Definition at line 96 of file ads131m0x.h.

◆ window_ms_

uint32_t esphome::ads131m0x::ADS131M0x::window_ms_ {100}
protected

Definition at line 89 of file ads131m0x.h.

◆ window_sequence_

uint32_t esphome::ads131m0x::ADS131M0x::window_sequence_ {0}
protected

Definition at line 99 of file ads131m0x.h.


The documentation for this class was generated from the following files: