Arduino library for TI ADS1258 (24-bit) and ADS1158 (16-bit) SPI ADCs. Provides register-level access plus helpers for common configuration and measurements.
- Supports ADS1258 (24-bit) and ADS1158 (16-bit)
- Read/Write/Update register helpers (read-modify-write)
- Config setters for CONFIG0/CONFIG1 (channel mode, bypass, chop, clock out, status byte, idle mode, delay, bias current, data rate)
- Single read or pulse conversion flows
- Optional status byte handling
#include <ADS1X58.h>
// SPI instance, chip select, vref volts
ADS1X58 adc(&SPI, ADC_TYPE::ADS1258, 10, 2.5f);
void setup() {
SPI.begin();
adc.setStatusByte(ADS1X58::STAT_EN); // include status byte in reads
adc.setChannelMode(ADS1X58::MUXMODE_AUTO_SCAN);
adc.setDataRate(ADS1X58::DRATE_11); // fastest
}
void loop() {
float v = adc.readVoltage();
// use v ...
}- Auto-Scan Mode: The ADC cycles through a pre-selectable list of channels automatically. Configure using
setChannelMode(MUXMODE_AUTO_SCAN), then enable channels via the MUX registers (e.g., writeMUXSG0/MUXSG1for single-ended, orMUXDIFfor differential). - Fixed-Channel Mode: The ADC repeatedly converts a single channel. Configure using
setChannelMode(MUXMODE_FIXED_CHANNEL)and select the input inREG_MUXSCH(AINP on bits [7:4], AINN on bits [3:0]).
Example:
adc.setChannelMode(ADS1X58::MUXMODE_AUTO_SCAN);
// Enable AIN0..AIN15 single-ended in auto-scan (helper enables all)
adc.enableSingleEndedInputsOnly();
adc.setChannelMode(ADS1X58::MUXMODE_FIXED_CHANNEL);
// Select AIN0 (P) vs AIN1 (N): write to REG_MUXSCH via updateRegister()
// adc.updateRegister(ADS1X58::REG_MUXSCH, ADS1X58::MASK_MUXSCH_AINP|ADS1X58::MASK_MUXSCH_AINN, (0x0<<4)|0x1);- Start Pin: Set the Start Pin to HIGH to trigger conversion. Will continuously take new samples if left HIGH. If ADC is in Auto-Scan mode it will automatically index the next channel. Use DRDY and call
readChannelDataCommand()orreadChannelDataDirect()to fetch the latest result or look at the status byteNEW, see. - Pulse Conversion (single-shot): Send
CMD_PULSE_CONVERTto start a single conversion; library helper:startPulseConversion(). After DRDY, read with one of the read modes.
- Direct Data Read: Wait for DRDY and then use
readChannelDataDirect(). No command byte (faster); just hold DIN steady for the first 3 SCLK edges, then clock out data. Risk of corruption if data is not read before the next DRDY. - Command Data Read: Library uses this in
readChannelDataCommand(). Can be read even during DRDY transistion (safer). SendsCMD_DATA_READ_COMMAND(with optionalCMD_MUL_EN) and then clocks out data.
- Optional status byte, toggle with
setStatusByte(STAT_EN|STAT_DIS):- Bit7
NEWnew data, Bit6OFVovervoltage, Bit5SUPPLYlow AVDD warning, Bits[4:0]CHIDchannel ID
- Bit7
- Data bytes: MSB→LSB
- ADS1258: 3 data bytes (24-bit two's complement); sign-extend from bit 23
- ADS1158: 2 data bytes (16-bit two's complement); sign-extend from bit 15
- is handled via
ADS1X58_ChanDatastruct
CONFIG0:
setInactivityResetTimer(SPIRST_LONG|SPIRST_SHORT)setChannelMode(MUXMODE_AUTO_SCAN|MUXMODE_FIXED_CHANNEL)setBypassMode(BYPAS_INTERNAL|BYPAS_EXTERNAL)setClockOutput(CLKENB_EN|CLKENB_DIS)setChopMode(CHOP_EN|CHOP_DIS)setStatusByte(STAT_EN|STAT_DIS)
CONFIG1:
setIdleMode(IDLMOD_SLEEP|IDLMOD_STANDBY)setConversionDelay(DLY_0 ... DLY_48)setSensorBiasCurrent(SBCS_OFF|SBCS_SMALL|SBCS_LARGE)setDataRate(DRATE_00 ... DRATE_11)
Helpers exist to read internal measurements: measVcc(), measGain(), measVref(), measTempC(), measOffset(). These temporarily adjust configuration, perform a pulse conversion, validate CHID, then restore registers.
MIT