ADS1258EVM-PDK: Anloge to digital

Part Number: ADS1258EVM-PDK
Other Parts Discussed in Thread: ADS1258

Tool/software:

 I am trying to connect an ADS1258 ADC converter to an Arduino Mega 2560 microcontroller. My goal is to apply a signal to ADS1258, connect ADS1258 to Arduino and Arduino to a computer, and read the time-variant voltage on the computer. fixed mode I am doing. The connection as follow:

Power:
3.3 V (ADC J5.9) to lab power source
5 V (ADC J5.3) to lab power source
GND (ADC J5.5) to lab power source
Signal wires:
A 20 Hz, 2 Vpp sinusoidal signal is applied on A0, A1 (ADC diff0) by a function generator
SCLK(ADC J6.3, input) to SLK(controller 52, output)
CS(ADC J6.7, input) to SS(controller 53, output)
DIN(ADC J6.11, input) to MOSI(controller 51, output)
DOUT(ADC J6.13, output) to MISO(controller 50, input)
DRDY(ADC J6.15, output) to INT(controller 2, input)
USB cable:
Arduino to computer
All ADC converter configuration setting is default. My arduino code as follow:

#include <SPI.h>
const int DRDY=2;
const int DOUT=50;
const int DIN=51;
const int SCLK=52;
const int CS=53;

/* ADS1258 minimal FIXED MODE driver (single‑ended AIN0…AIN7)*/
#pragma once
#include <SPI.h>

class ADS1258 {
public:
ADS1258(uint8_t cs, uint8_t drdy, uint8_t start, uint8_t reset)
: _cs(cs), _drdy(drdy), _start(start), _reset(reset) {}

void begin() {
pinMode(_cs, OUTPUT); digitalWrite(_cs, HIGH);
pinMode(_start, OUTPUT); digitalWrite(_start, LOW);
pinMode(_reset, OUTPUT); digitalWrite(_reset, HIGH);
pinMode(_drdy, INPUT);

SPI.begin();
SPI.beginTransaction(SPISettings(4000000UL, MSBFIRST, SPI_MODE0));

_hardwareReset(); // step 1
_writeRegisters(); // step 3
digitalWrite(_start, HIGH); // step 4
}

/* Blocks until DRDY falls, then returns raw 24‑bit sample and channel id */
bool readSample(int32_t &code, uint8_t &channelId) {
if (digitalRead(_drdy)) return false; // not ready yet

digitalWrite(_cs, LOW);
_spiTransfer(CMD_RDATA); // 0x30
uint8_t status = _spiTransfer(0x00);
uint32_t d = 0;
d |= (uint32_t)_spiTransfer(0x00) << 16;
d |= (uint32_t)_spiTransfer(0x00) << 8;
d |= (uint32_t)_spiTransfer(0x00);
digitalWrite(_cs, HIGH);

channelId = status & 0x08; // CHID[4:0] :contentReference[oaicite:8]{index=8}
/* sign‑extend 24‑bit two’s‑complement to 32 bit */
if (d & 0x800000) d |= 0xFF000000;
code = (int32_t)d;
return true;
}

private:
/* -------- low‑level helpers -------- */
static constexpr uint8_t CMD_RESET = 0xC0; // C[2:0]=110, MUL/A=0
static constexpr uint8_t CMD_WREG = 0x60; // C[2:0]=011, MUL=1, A=0000
static constexpr uint8_t CMD_RDATA = 0x30; // C[2:0]=001, MUL=1

void _hardwareReset() {
digitalWrite(_reset, LOW); delayMicroseconds(10);
digitalWrite(_reset, HIGH); delay(2); // ≥218 fCLK cycles :contentReference[oaicite:9]{index=9}
}

void _writeRegisters() {
static const uint8_t regImage[] = {
0x22, // CONFIG0 – status enabled, auto‑scan, STAT=1 :contentReference[oaicite:10]{index=10}
0x80, // CONFIG1 – DRATE[1:0]=11 (23.7 kSPS/ch) :contentReference[oaicite:11]{index=11}
//0x00, // MUXDIF – no differential pairs
0x08, // MUXCH – enable AIN0…7
// 0x00 // MUXSG1 – no AIN8…15
};
digitalWrite(_cs, LOW);
_spiTransfer(CMD_WREG);
for (uint8_t b : regImage) _spiTransfer(b);
digitalWrite(_cs, HIGH);
}

uint8_t _spiTransfer(uint8_t val) { return SPI.transfer(val); }

uint8_t _cs, _drdy, _start, _reset;
};

#include "ADS1258.h"
ADS1258 adc(53, 2, 4, 54); // CS=10, DRDY=2, START=3, RESET=4

void setup() {
Serial.begin(115200);
adc.begin();
}

void loop() {
int32_t code; uint8_t channelId;
if (adc.readSample(code,channelId)) {
float v = (code / 8388608.0) * 5.0; // example for VREF = 2.5 V unipolar
Serial.print("CH"); Serial.print(channelId);
Serial.print(": "); Serial.println(v, 6);
}
}

but it is not measuring the AIN0 instead on DOUT random number is appearing.   Can you please help 

  • Hi latifa Heydari,

    Have you confirmed that you are able to read and write registers correctly? This should confirm that the ADC is powered properly and the clock is working

    If so, can you read back the STATUS byte of the "bad" data to confirm if the CHID bits are correct and that the ADC is scanning through the channels in the correct order?

    Can you share a schematic of your system?

    If this turns out to be a communication issue you will also need a logic analyzer to help diagnose

    -Bryan

  •  

    Hi Bryan, above is the image, 

    Yellow= DOUT

    Green= DIN

    Blue= CS

    Purple= SCLK

    I Can not read or write the register, serial monitor reads:

    CH0: 0.000000
    CH0: -5.000000 .186768
    CH0: 0.078125
    CH0: 1.250000
    CH8: -1.25000.000000
    CH0: 0.019531
    CH8: -2.343674
    CH0: 0.253906
    CH0: 0.292969
    CH0: 0.186768
    CH0: 0.078125
    CH0: 1.250000
    CH8: -1.250000
    CH0: 0.00241
    ⸮1

    What you mean by schematic? 

  • Hi latifa Heydari,

    Your image unfortunately did not post correctly. Please try again, and you can double check your post to make sure the image is visible after you hit "Reply"

    "Schematic" means the schematic image of the PCB with ADS1258 that you are using to connect to the Arduino.

    -Bryan