ADS1256 High Precision AD/DA board Code Problem

Hello Everyone,

I have an ADS1256 High-Precision AD/DA shield for Raspberry Pi.
I have connected it to an Arduino Uno.

fig.1 shows my adc board.

fig.2 & fig.3 shows connections.

my code is:

/* ADS1256
    CLK  - pin 13
    DIN  - pin 11 (MOSI)
    DOUT - pin 12 (MISO)
    CS   - pin 10
    DRDY - pin 9
    RESET- pin 8 (or tie HIGH?)
    DVDD - 3V3
    DGND - GND
*/

#define cs 10 // chip select
#define rdy 9 // data ready, input
#define rst 8 // reset pin
#define pwd 7 // power down

#define SPISPEED 1000000
              // 1250000

#include <SPI.h>

void setup()
{
  Serial.begin(115200);
  
  pinMode(cs, OUTPUT);
  digitalWrite(cs, LOW); // tied low is also OK.
  pinMode(rdy, INPUT);
  pinMode(rst, OUTPUT);
  digitalWrite(rst, LOW);
  delay(1); // LOW at least 4 clock cycles of onboard clock. 100 microsecons is enough
  digitalWrite(rst, HIGH); // now reset to deafult values
  
  delay(500);
  SPI.begin(); //start the spi-bus
  delay(500);

  //init

  digitalWrite(pwd, LOW);
  //while (digitalRead(rdy)) {}  // wait for ready_line to go low
  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
  delayMicroseconds(10);

  //Reset to Power-Up Values (FEh)
  SPI.transfer(0xFE);
  delayMicroseconds(100);
  
  byte status_reg = 0 ;  // address (datasheet p. 30)
  //PGA SETTING
  //1 ±5V
  //2 ±2.5V
  //4 ±1.25V
  //8 ±0.625V
  //16 ±312.5mV
  //32 ±156.25mV
  //64 ±78.125mV
  //byte status_data = 0x01; //status: Most Significant Bit First, Auto-Calibration Disabled, Analog Input Buffer Disabled 
  byte status_data = 0b00000110;
  SPI.transfer(0x50 | status_reg);
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(status_data);   // write the databyte to the register
  delayMicroseconds(10);
  

  byte adcon_reg = 2; //A/D Control Register (Address 02h)
  byte adcon_data = 0x20; // 0 01 00 000 => Clock Out Frequency = fCLKIN, Sensor Detect OFF, gain 1
  SPI.transfer(0x50 | adcon_reg);
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(adcon_data);   // write the databyte to the register
  delayMicroseconds(10);


  // Set sampling rate
  byte drate_reg = 3;
  byte drate_data = 0b10000010; // 100SPS
  SPI.transfer(0x50 | drate_reg);
  SPI.transfer(0x00);
  SPI.transfer(drate_data);
  delayMicroseconds(10);

  SPI.transfer(0xF0);
  delay(5000);
  
// digitalWrite(cs, HIGH);
  
  Serial.println("configured, starting");
}


void loop()
{
  unsigned long adc_val =0;
  float mV = 0;

  // digitalWrite(cs, LOW);
  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
  delayMicroseconds(10);

  //while (digitalRead(rdy)) {} ;

  byte data = 0b00000001;//DIFF 1
  SPI.transfer(0x50 | 1); // MUX register
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(data);   // write the databyte to the register
  delayMicroseconds(10);

  //SYNC command 1111 1100
  SPI.transfer(0xFC);
  delayMicroseconds(10);
  
  //WAKEUP 0000 0000
  SPI.transfer(0x00);
  delayMicroseconds(10);
  
  SPI.transfer(0x01); // Read Data 0000  0001 (01h)
  delayMicroseconds(10);
  
  adc_val = SPI.transfer(0);
  adc_val <<= 8; //shift to left
  adc_val |= SPI.transfer(0);
  adc_val <<= 8;
  adc_val |= SPI.transfer(0);
  
  delayMicroseconds(10);
  
  // digitalWrite(cs, HIGH);
  SPI.endTransaction();

  //The ADS1255/6 output 24 bits of data in Binary Two's
  //Complement format. The LSB has a weight of
  //2VREF/(PGA(223 − 1)). A positive full-scale input produces
  //an output code of 7FFFFFh and the negative full-scale
  //input produces an output code of 800000h. 
  if(adc_val > 0x7fffff){ //if MSB == 1
    adc_val = (16777215ul - adc_val) + 1; //do 2's complement
    //Serial.print("-");
  }
  else
  {
    //Serial.print("+");
  }
  mV = adc_val*0.000596046; // 8388607 = +5.000v / 
  Serial.println(mV);

  delay(100);
}

As I want to read to data from 1 channels with single ended measurements. While analog input 1 is connected to the variable resistance (embedded on the ADS1256 High-Precision AD/DA shield board) and i change it but i get only 0 as a output in the serial monitor.

If anyone can guide me here it can help me to complete my project.
It would be really helpful to get some guidance.

Thanks
:slight_smile:

If this is the schematic for your board: https://www.waveshare.com/w/upload/2/29/High-Precision-AD-DA-board.pdf

and you have the jumpers set as in your picture, it looks like the channel 1 (AIN1) is connected to the onboard photocell. The potentiometer appears to be connected to channel 0 (AIN0).

You should probably hold P4 (/CS1) high (if you are not already doing so) to prevent the DAC interfering with the SPI bus.

Is that code your own invention? If you found it somewhere, post a link to that site.

Thanks for your attention :slight_smile:
yes, this is the schematic for my board.

Forgive my carelessness. The channel 1 (AIN1) is connected to the onboard photocell and The potentiometer is connected to channel 0 (AIN0).

I holded P4 high, But still not receiving data.

I measured voltage on pin 21 ads1256. Why the DRDY output pin is always HIGH (3.3 V)?

The code stops when it reaches the following line

while (digitalRead(rdy)) {}  // wait for ready_line to go low

I think my problem is that the DRDY pin is not be LOW!

This code is not for me and I will send the link to the author.

Thanks

I did not notice before but you appear to have commented out the chip select (cs)

// digitalWrite(cs, LOW);
SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
  . . . 
  . . . 
// digitalWrite(cs, HIGH);
SPI.endTransaction();

This must be brought low before an SPI.beginTransaction and high at the SPI.endTransaction();
This could explain why the program appears to hang.

You could also try changing this:

 pinMode(rdy, INPUT);

to:

pinMode(rdy, INPUT_PULLUP);

Thanks for replay

I did the changes that you made, but still the results are as before and I have not received any data

The code does not run from the following line to the next:

while (digitalRead(rdy)) {}

any body help me???

Google for "ads1256 arduino" and you may find something which helps.

You haven't provided a link to the code you have found, it is relatively complex, and the board is intended for a Raspberry Pi which makes it difficult to help you.

Maybe look at the datasheet for the ads1256 http://www.ti.com/lit/ds/symlink/ads1255.pdf (see DIGITAL INTERFACE CONNECTIONS from page 29).
Attempt something relatively simple to start with like retrieving the contents of the status register.

Special with that board you are using, and as mentioned before, is that there another SPI device on the bus (DAC) so it has to be disabled.