Arduino Forum

Using Arduino => Sensors => Topic started by: nchazarra on May 09, 2016, 08:10 pm

Title: Problem with ADS1256 board
Post by: nchazarra on May 09, 2016, 08:10 pm
Hi to everybody,

This is my first message to the forum. I've been reading it a lot since I started a year ago working with Arduino for my geology projects, and first, I would like to say thanks for the big community support I always find in the board.

Now I've got one question. Two weeks ago I bought an ADS1256 board (the one of the attached image). I've been struggling to make it work and get some readings, but I didn't succeed. I tried to use the ADS1213 library, and also the ADS1248, but the only values I've got are -1 or 0 with an Arduino UNO board and also with a DUE.

Anybody can help?

Thanks in advance.

Title: Re: Problem with ADS1256 board
Post by: knut_ny on May 09, 2016, 10:11 pm
for some reason I cannot download your picture.  post a link to shop?   Show connections & code
Title: Re: Problem with ADS1256 board
Post by: nchazarra on May 09, 2016, 10:18 pm
I bought this model: http://www.ebay.com/itm/ADS1256-24Bits-ADC-AD-Module-Communication-Modules-Capture-Board-Module-Kit-/151512712677

I was using the code from the ADS1213 library:

Code: [Select]
// This sketch demonstrates the use of the ADS1213 library by first initializing
// it with the neccesary parameters, then reading it every half second while cycling through the channels.

#include <ADS1213.h>

ADS1213 ADC_ext(16,false,13,11,2,0);
// clock speed MHz, true=offset binary (false=two's complement (can be negative)), SCLK pin, IO pin, DRDY pin, CS pin (0 if not in use)

void setup() {
  Serial.begin(115200);
  ADC_ext.CMRwrite(3,B001,1,1,255);
  // channel 3, mode 001 (self-calibration), gain 1, TMR 1, DR 255
  Serial.println("Done with setup");
}

void loop() {
  static byte Channel=1; // Static makes sure it doesn't get re-initialized every time
  Serial.print(Channel,DEC); Serial.print(" ch ");
  Serial.println(ADC_ext.readSigned(3),DEC); // Read and print the signed value
  Channel += 1;
  if (Channel>4) Channel = 1;
  ADC_ext.channel(Channel); // Set the current (incremented) channel by using the channel() function
  delay(500);
}


The connections were the SCLK to the pin 13, IO to the pin 11, DRDY to the pin 2, and tested the cable select option connected to a pin, and without any connection, but got the same results.
Title: Re: Problem with ADS1256 board
Post by: knut_ny on May 09, 2016, 10:50 pm
I believe you found library (http://arduino.stackexchange.com/questions/4919/references-e-g-libraries-and-tutorials-for-connecting-the-24-bit-ads1256-adc) from here.

Chips are very alike, so the lib may work.  Choose other pin (than pin 0) for CS
Channel 3 is read in your code. (not full bridge with differential inputs)
Title: Re: Problem with ADS1256 board
Post by: nchazarra on May 09, 2016, 11:19 pm
I just continue to have readings like -1. When I get my hands close to the Analog pins, the readings change to 0, but nothing else.
Title: Re: Problem with ADS1256 board
Post by: nchazarra on May 10, 2016, 01:02 am
Now, using the ADS1213 I got lectures, but only when I put my hands over the geophone, using this code, but the lectures don't make any sense to me.:
Code: [Select]
#include <ADS1213.h>

ADS1213 ADC_ext(16,true,13,10,3,0);
// clock speed MHz, true=offset binary (false=two's complement (then the output can be negative)), SCLK pin, IO pin, DRDY pin, CS pin (0 if not in use)

void setup() {
  Serial.begin(115200);
  ADC_ext.CMRwrite(3,B001,1,1,50);
  // channel 3, mode 001 (self-calibration), gain, TMR, Decimation Ratio
  Serial.println("Done with setup");
}

const int NoOfSamples = 60; // Warning: if set too high, DeviationSqSum may overflow!
// This will happen sooner when the real standard deviation is higher.
unsigned long Values[NoOfSamples];

void loop() {
 
    double lec=ADC_ext.read(B000,3);
    Serial.println(lec);

  delay(20); // Wait a second to avoid overflowing the serial monitor with data
}


Title: Re: Problem with ADS1256 board
Post by: knut_ny on May 10, 2016, 07:46 pm
Try using hardware SPI.. pins clk 13, MISO 12 and MOSI 11
I'll download https://github.com/Flydroid/ADS12xx-Library (https://github.com/Flydroid/ADS12xx-Library) this one and take a peek inside..
-----------
There in an .ino-file included..  It tells you to alter the "ads12xx.h"
(I can see it needs to be changed)
In the example, change RDY, CS and Start to match any digital pin (except 11..13)
Title: Re: Problem with ADS1256 board
Post by: nchazarra on May 11, 2016, 08:37 pm
Knut_ny,

I've tried this library, but the program that is served as an example it doesn't work for me, just gets stuck after selecting any of the commands.

I see also that my board doesn't have a START pin, but I obviously must be doing anything else wrong.

My plan is using this board to get the data from three geophones as differential inputs to get a higher dinamic range than when I use a 16 bit ADC.

Thanks for your help.
Title: Re: Problem with ADS1256 board
Post by: knut_ny on May 11, 2016, 09:14 pm
The full datasheet has all info needed to program and read the chip.
RDY-line tells when a convertion is done and data can be fetched.  If the input is from an ocsillating source it may be difficult to interpret the reading.
Maybe some enveloping can be done before reading. (to read interval peak values)

What kind of signals/levels do you det from the geophones?   frequency?

..and take a look at ebay.. HX711  (differential, amplifying inputs 32/64/128 times) @<$3
Title: Re: Problem with ADS1256 board
Post by: nchazarra on May 11, 2016, 09:53 pm
The problem is that I don't have enough programming background, that is why I tried to use these already made libraries.

I usually read frequencies under 50 Hz, but I use three geophones simultaneously, two horizontal and one vertical. The HX711 only have two differential inputs, but I'm gonna give it a try.

Thanks for the advice!
Title: Re: Problem with ADS1256 board
Post by: knut_ny on May 11, 2016, 10:17 pm
!! See the HX711 datasheet.. You usually use only one channel as it it related to ampl. factor
Title: i also have problem to read the ads1256.but read and write the register is work
Post by: yatinpurohit on May 17, 2016, 04:50 pm
hello

ADS1256 register read and write work properly but i have problem to read the data from ads1256 its show garbage value.

i send my code here.

#include <SPI.h>
#define DRDY_PIN 2
#define CS_PIN 7
#define NOP 0xFF
#define MISO_PIN 12
#define MOSI_PIN 11
#define SCK_PIN 13
#define WREG 0x50
#define RREG 0x10
#define RDATA 0x01 //Read data once
#define RDATAC 0x03 //Read data continously
#define SDATAC 0x0F //Stop reading data continously
#define WAKEUP 0x00 //Exit Sleep Mode
#define SYNC 0xFC
#define NOP 0xFF
#define ORDER_MSB // Most significant Bit first (default)
#define SPI_SPEED 4800000
#define PGA 1 // Programmable Gain = 1
#define VREF 2.5 // Internal reference of 2.048V
#define VFSR VREF*2/PGA
#define FSR (((long int)1<<23)-1)


//const int dataReadyPin = 6;
volatile byte MSB;
volatile byte data;
volatile byte LSB;
//volatile char SPI_RX_Buff[3];
//volatile byte *SPI_RX_Buff_Ptr;
uint8_t CONFIG_REG0_ADDRESS;
uint8_t CONFIG_REG1_ADDRESS;
uint8_t CONFIG_REG2_ADDRESS;
uint8_t CONFIG_REG3_ADDRESS;
uint8_t CONFIG_REG4_ADDRESS;
uint8_t CONFIG_REG5_ADDRESS;
uint8_t CONFIG_REG6_ADDRESS;
uint8_t CONFIG_REG7_ADDRESS;
uint8_t CONFIG_REG8_ADDRESS;
uint8_t CONFIG_REG9_ADDRESS;
uint8_t CONFIG_REG10_ADDRESS;
uint8_t Config_Reg0 ;
uint8_t Config_Reg1 ;
uint8_t Config_Reg2;
uint8_t Config_Reg3 ;
uint8_t Config_Reg4 ;
uint8_t Config_Reg5 ;
uint8_t Config_Reg6;
uint8_t Config_Reg7 ;
uint8_t Config_Reg8 ;
uint8_t Config_Reg9;
uint8_t Config_Reg10 ;




volatile int DRDY_state;

void setup()
{
delayMicroseconds(500);
delayMicroseconds(500);
pinMode(MOSI_PIN, OUTPUT);
pinMode(MISO_PIN, INPUT);
pinMode(CS_PIN, OUTPUT);
pinMode(DRDY_PIN, INPUT);
pinMode(SCK_PIN, INPUT);
digitalWrite(CS_PIN, HIGH);
digitalWrite(SCK_PIN, LOW);
volatile int DRDY_state = HIGH;
SPI.begin();
Serial.begin(9600);
void writeRegister(uint8_t address, uint8_t value);
uint8_t readRegister(uint8_t address);
SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1));
void DRDY_Interuppt();
attachInterrupt(digitalPinToInterrupt(DRDY_PIN), DRDY_Interuppt,FALLING);
CONFIG_REG0_ADDRESS=0x00;
CONFIG_REG1_ADDRESS=0x01;
CONFIG_REG2_ADDRESS=0x02;
CONFIG_REG3_ADDRESS=0x03;
CONFIG_REG4_ADDRESS=0x04;
CONFIG_REG5_ADDRESS=0x05;
CONFIG_REG6_ADDRESS=0x06;
CONFIG_REG7_ADDRESS=0x07;
CONFIG_REG8_ADDRESS=0x08;
CONFIG_REG9_ADDRESS=0x09;
CONFIG_REG10_ADDRESS=0x0A;
delay(100);
writeRegister(0x00, 0x01);
delayMicroseconds(50);
writeRegister(0x01, 0x0F);
delayMicroseconds(50);
writeRegister(0x02, 0x20);
delayMicroseconds(50);
writeRegister(0x03, 0xA2);
delayMicroseconds(50);
writeRegister(0x04, 0xE0);
delayMicroseconds(50);
writeRegister(0x05, 0x00);
delayMicroseconds(50);
writeRegister(0x06, 0x00);
delayMicroseconds(50);
writeRegister(0x07, 0x00);
delayMicroseconds(50);
writeRegister(0x08, 0x00);
delayMicroseconds(50);
writeRegister(0x09, 0x00);
delayMicroseconds(50);
writeRegister(0x0A, 0x00);
delayMicroseconds(50);
// digitalWrite(CS_PIN,HIGH); //release chip, signal end transfer

Config_Reg0 = readRegister(CONFIG_REG0_ADDRESS);
delayMicroseconds(50);
Config_Reg1 = readRegister(CONFIG_REG1_ADDRESS);
delayMicroseconds(50);
Config_Reg2 = readRegister(CONFIG_REG2_ADDRESS);
delayMicroseconds(50);
Config_Reg3 = readRegister(CONFIG_REG3_ADDRESS);
delayMicroseconds(50);
Config_Reg4 = readRegister(CONFIG_REG4_ADDRESS);
delayMicroseconds(50);
Config_Reg5 = readRegister(CONFIG_REG5_ADDRESS);
delayMicroseconds(50);
Config_Reg6 = readRegister(CONFIG_REG6_ADDRESS);
delayMicroseconds(50);
Config_Reg7 = readRegister(CONFIG_REG7_ADDRESS);
delayMicroseconds(50);
Config_Reg8 = readRegister(CONFIG_REG8_ADDRESS);
delayMicroseconds(50);
Config_Reg9 = readRegister(CONFIG_REG9_ADDRESS);
delayMicroseconds(50);
Config_Reg10 = readRegister(CONFIG_REG10_ADDRESS);
delayMicroseconds(50);
delay(100);


Serial.println("Config_Reg : ");
Serial.println(Config_Reg0,HEX);
Serial.println(Config_Reg1,HEX);
Serial.println(Config_Reg2,HEX);
Serial.println(Config_Reg3,HEX);
Serial.println(Config_Reg4,HEX);
Serial.println(Config_Reg5,HEX);
Serial.println(Config_Reg6,HEX);
Serial.println(Config_Reg7,HEX);
Serial.println(Config_Reg8,HEX);
Serial.println(Config_Reg9,HEX);
Serial.println(Config_Reg10,HEX);
Serial.println(" ");
delay(200);
digitalWrite(CS_PIN, HIGH);

}


void loop()
{

delayMicroseconds(50);
delayMicroseconds(50);
long int bit32;
long int bit24;
byte *config_reg;
long int regData;


if((digitalRead(DRDY_PIN)) == LOW) // Wait for DRDY to transition low

{
long int regData;
digitalWrite(CS_PIN, LOW); //Pull SS Low to Enable Communications with ADS1247
delayMicroseconds(10);
// RD: Wait 25ns for ADC12xx to get ready
// SPI.transfer(0x51);
//SPI.transfer(0x00);
// SPI.transfer(0x0F);
// writeRegister(0x01,0x43);
//Issue RDATA
SPI.transfer(SDATAC);
SPI.transfer(SYNC);
SPI.transfer( WAKEUP);
SPI.transfer( RDATAC);
delayMicroseconds(1);
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
bit24 <<= 8;
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
bit24 <<= 8;
bit24 |= SPI.transfer(NOP);
delayMicroseconds(1);
//Serial.println(regData,HEX);
bit24= ( bit24 << 8 );
bit32 = ( bit24 >> 8 );
// Converting 24 bit two's complement to 32 bit two's complement
delayMicroseconds(10);
//Serial.println(bit24,HEX);

float Vout = (float)((bit32*VFSR*1000)/FSR); //In mV

delay(300);

Serial.print("Vout in mV : ");
Serial.print(Vout);
Serial.print(" 32bit HEX : ");
Serial.println(bit32,HEX);


}
}



void writeRegister(uint8_t address, uint8_t value)
{
delayMicroseconds(10);
// waitforDRDY();
//SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with SPI_SPEED, MSB first, SPI Mode1
digitalWrite(CS_PIN, LOW);
delayMicroseconds(10);
SPI.transfer(WREG | address); // send 1st command byte, address of the register
SPI.transfer(0x00); // send 2nd command byte, write only one register
SPI.transfer(value); // write data (1 Byte) for the register
delayMicroseconds(10);
digitalWrite(CS_PIN, HIGH);
}




uint8_t readRegister(uint8_t address)
{
uint8_t data;
// waitforDRDY();
// SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with 4Mhz clock, MSB first, SPI Mode0
digitalWrite(CS_PIN, LOW);
delayMicroseconds(10);
SPI.transfer(RREG | address); // send 1st command byte, address of the register
SPI.transfer(0x00); // send 2nd command byte, read only one register
delayMicroseconds(10);
data = SPI.transfer(NOP); // read data of the register
delayMicroseconds(10);
digitalWrite(CS_PIN, HIGH);
//digitalWrite(_START, LOW);
// SPI.endTransaction();
return data;

}



void waitforDRDY()
{
while (DRDY_state)
{
continue;
}
noInterrupts();
DRDY_state = HIGH;
interrupts();
}

//Interrupt function
void DRDY_Interuppt()
{
DRDY_state = !DRDY_state;
// state = !state;
}



output on serial is








so garbage value is come......

so i not able to understand where i did mistake......
Title: Re: Problem with ADS1256 board
Post by: knut_ny on May 19, 2016, 11:53 am
Read PM. - continue here with code and results
Title: Re: Problem with ADS1256 board
Post by: raltom on May 20, 2016, 09:40 am
Hi,
The library ADS12xx.h doesn't work for me; my board haven't the pin START;
Title: Re: Problem with ADS1256 board
Post by: knut_ny on May 20, 2016, 10:03 am
I sent this to "nchazarra".
Compare with datasheet and other libs.
The speed_setting 14MHz may be incorrect for the UNO.
Code: [Select]
/* ADS1256, datasheet: http://www.ti.com/lit/ds/sbas288j/sbas288j.pdf
compare: https://github.com/Flydroid/ADS12xx-Library/blob/master/ads12xx.cpp
    connections to Atmega328 (UNO)

    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

    Analog ch0 (input 0,1)
    Analog ch1 (input 2,3)
    Analog ch2 (input 4,5)
    (Analog ch3 (input 6,7))
*/

#define cs 10 // chip select
#define rdy 9 // data ready, input
#define rst 8 // may omit

// ** asd1256 Register map and data to write **
#define status_reg 0   // address (datasheet p. 30)
#define status_data 0x01 // default contents after reset (no need to write this)

#define mux_reg 1
//  mux_data to be changed while running, to select input ports

#define adcon_reg 2
#define adcon_data 0x24 // 0 01 00 100 => clk_out(default), sensor detect OFF, gain 16 (p.31)

#define drate_reg 3
#define drate_data 0x82 // => 100 SPS (samples/secons)

#include <SPI.h>

byte i; // general use

void setup()
{
  SPI.begin(); //start the spi-bus
  pinMode(cs, OUTPUT);
  digitalWrite(cs, LOW); // tied low is also OK.
  pinMode(rdy, INPUT);
  pinMode(rst, OUTPUT);
  Serial.begin(115200);
  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(1); // unsure if needed
  // now set working parameters
  writereg(status_reg, status_data); // parameters defined on top
  writereg(adcon_reg, adcon_data);
  writereg(drate_reg, drate_data);
}

void writereg(byte reg_num, byte data) // write to a single register
{
  // digitalWrite(cs, LOW);
  while (rdy) {}  // wait for ready_line to go low
  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE1)); // start SPI
  delayMicroseconds(10);
  SPI.transfer(0x50 | reg_num); // dataseheet p.34
  SPI.transfer(0x00);   // 2nd command byte
  SPI.transfer(data);   // write tge databyte to the register
  delayMicroseconds(10);
  SPI.endTransaction();
  // digitalWrite(cs, HIGH);
}

byte readreg(byte reg_num)  // read from a single register
{
  // digitalWrite(cs, LOW);  // cs is tied low for now? Theese two lines may be added if other components uses SPI-bus
  while (rdy) {}  // wait for ready_line to go low
  SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE1)); // start SPI
  byte bufr;
  while (rdy) {}  // wait for ready_line to go low
  delayMicroseconds(10);
  SPI.transfer(0x10 | reg_num); // send 1st command byte, address of the register
  SPI.transfer(0);  // one byte only
  delayMicroseconds(10);
  bufr = SPI.transfer(0xff); // read data from register (dummy parameter)
  delayMicroseconds(10);
  SPI.endTransaction();
  // digitalWrite(cs, HIGH);
  return bufr;
}

void loop()
{
  long adc_val; // store reading
  //Read 4 channels from ads1256
  for (i = 0; i < 5; i += 2)
  {
    // digitalWrite(cs, LOW);
    adc_val = 0;
    while (rdy) {} ;
    // send command - select ADC-channel 0000 0001 / 0010 0011 / 0100 0101
    SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE1)); // start SPI
    delayMicroseconds(10);
    writereg(mux_reg, i << 4 | i + 1 ); // positive to analog 0,2,4,6, Neg to 1,3,5,7
    while (rdy) {} ;
    SPI.transfer(1); // command for: READ DATA  (p.34)
    delayMicroseconds(10);// read three bytes (adc-value)
    adc_val = SPI.transfer(0)<<8;
    //delayMicroseconds(10); // needed ?
    adc_val |= SPI.transfer(0);
    //delayMicroseconds(10); // ??
    adc_val <<= 8;
    adc_val |= SPI.transfer(0);
    delayMicroseconds(10);
    // digitalWrite(_CS, HIGH);
    SPI.endTransaction();
    Serial.print(adc_val);
    Serial.print(" / ");
    // digitalWrite(cs, HIGH);
  }
  Serial.println();
}

Title: Re: Problem with ADS1256 board
Post by: dariosalvi on Jun 17, 2016, 07:58 pm
Hi,

I have the same board in the picture of the first post and I am trying to make this last code work.

I am puzzled a bit by it.
First, I thing that the while(rdy) should really be while (digitalRead(rdy)).
Second, I don't understand the for loop.
It says it wants to read 4 channels, but it iterates only 3 times and I don't know why exactly that choice of values..

Can you make it a bit more explicit?

Thanks!
Title: Re: Problem with ADS1256 board
Post by: knut_ny on Jun 17, 2016, 08:48 pm
Thanks..
Quote
First, I thing that the while(rdy) should really be while (digitalRead(rdy)).
Of course it shall be..

If you read the compete post, u'll se that OP has only 3 channels used.
I have never seen that sensor, but belive that the code may be a good start..

Knut
Title: Re: Problem with ADS1256 board
Post by: dariosalvi on Jun 17, 2016, 11:17 pm
Thanks Knut.

I am reading the data sheet and the code is starting to make sense now.

In my case I need to convert a single-ended input, not a differential input.
As far as I understand it, I need to set the multiplex register to 8, which means selecting:
0000 (AIN0) 1000 (AINCOM)

I am not sure if I have got this right.

BTW, there is no AINCOM pin on the board, which makes me think that it is tied to some reference.


With the code as it is now, I get very unstable readings.

Here's an example of readings with AIN0 put to VCC (5V in my case):


16777198
16776701
16777200
0
0
16777200
16777200
16777199
16777202
16776701
16776701
16777200
16777200
0
8388608
16776701
16777198
0
8388608


any suggestion is more than welcome!

Title: Re: Problem with ADS1256 board
Post by: knut_ny on Jun 18, 2016, 02:19 pm
AINCOM = Analog Common => reference voltage for ALL inputs

If you've got max 4 analog values to read, you can use the differental setting. This allows for separate ref. voltage for all 4 inputs

A close look at your reading:
chech the binary pattern. compare with 2s compl. zero is 2^23
Title: Re: Problem with ADS1256 board
Post by: dariosalvi on Jun 18, 2016, 07:11 pm
Guys,

I think I've got it working!!

It's been a hard work of reverse engineering from different sources, schematics, and chinese strange documentations.

I am now finally able to measure the voltage at AIN0 (no differential, just voltage between 0 and 5V). The main problem with Knut's code was the SPI speed, it is way too high, I have brought it down to 1.2 MHz. Also, you need to do the 2's complement of the measured value.

I have done some tests with potentiometers and the values make sense.

Some things I have discovered:
- I think that the second row of pins, close to the AINx pins is the AINCOM. I don't know how to use it really, so I am leaving it floating.
- The DVDD and DGND pins should be connected to GND and 3.3V, but if you leave them floating it also seem to work.

Here's the code:

Code: [Select]

/* ADS1256, datasheet: http://www.ti.com/lit/ds/sbas288j/sbas288j.pdf
  compare: https://github.com/Flydroid/ADS12xx-Library/blob/master/ads12xx.cpp
    connections to Atmega328 (UNO)

    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 // may omit

#define SPISPEED 1250000
              // 1700000

#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(cs, 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
  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);
 
// digitalWrite(cs, HIGH);
 
  Serial.println("configured, starting");
}


void loop()
{
  unsigned long adc_val =0; // store reading

  // digitalWrite(cs, LOW);
  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
  delayMicroseconds(10);
  //The most efficient way to cycle through the inputs is to
  //change the multiplexer setting (using a WREG command
  //to the multiplexer register MUX) immediately after DRDY
  //goes low. Then, after changing the multiplexer, restart the
  //conversion process by issuing the SYNC and WAKEUP
  //commands, and retrieve the data with the RDATA
  //command.
  while (digitalRead(rdy)) {} ;

  byte channel = 0;
  byte data = (channel << 4) | (1 << 3); //AIN-channel and AINCOM
  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.println(adc_val);

  delay(500);
  // digitalWrite(cs, HIGH);
}
Title: Re: Problem with ADS1256 board
Post by: knut_ny on Jun 18, 2016, 09:10 pm
Nice !   I'm sure others will be very happy when u upload your final library .. to github ?
Title: Re: Problem with ADS1256 board
Post by: tinomk on Sep 15, 2016, 01:07 pm
Hi dariosalvi,

I tried your example and it is not clear what is the sampling rate you use?

Thanks,
Title: Re: Problem with ADS1256 board
Post by: Eheran on Dec 11, 2016, 12:52 am
So I got the code from pafe 1 to spit out some numbers too, but its messed up a lot.
dariosalvis code seems to be right so far.

But how to set the options like PGA, sample rate, buffer etc.?
And how to read the register map?
Title: Re: Problem with ADS1256 board
Post by: dariosalvi on May 02, 2017, 09:26 pm
Hello,

I have created a nicer code, a sort of library, but does not include all the functionalities of the chip.

I have uploaded it on this gist (https://gist.github.com/dariosalvi78/f2e990b4317199d235bbf5963c3486ae).
Feel free to fork it and improve it!
Title: Re: Problem with ADS1256 board
Post by: KeyChainz on Sep 29, 2017, 06:29 pm
Do you have a circuit diagram for this?

I am using your code, but I keep on reading 0's, so it could be a hardware wiring problem.

Thanks
Title: Re: Problem with ADS1256 board
Post by: anurag2508 on Feb 26, 2018, 06:46 am
Hello Everyone,

I am trying to interface High Precision DA/AD board ADS1256 with Arduino. The code I have taken from library. Actually I am able to read the data but the thing is I am not able to understand the settling time thing and How much settling time I should provide for each command. and also How do I figure what frequency and PGA to be set to read the data?

Thanks
Title: Re: Problem with ADS1256 board
Post by: hgpt on Apr 25, 2018, 12:47 pm
Hi!

Using an ADS1255 (basically the same IC as ADS1256) and dariosalvi code got my ADS1255 working (btw the sample code was missing "SPI.endTransaction();" at the end of the setup).

I've adapted the code a bit to match my setup and configured one more register (DRATE) in order to make sure the ADC is working at it's full 30kSPS potential and the results I'm getting are quite chaotic, making no sense at all:
Code: [Select]
72655
2966232813
3436158698
255799543
3473817828
534761477
3506425644
1627348985
4257216639
28320544
548220649
3772690109
3792572396
282054638
1610440670
268468467
64021071
1374023375
3174706
4043223809
95399897
871358517
1325613092
1325416659
4267691519
 

Does anyone know what's the problem?

Here is my code
Code: [Select]

#include <SPI.h>
#define SPISPEED 1250000

#define SCK   14
#define MOSI  12
#define MISO  27
#define DRDY  26
#define CS 5

#define WREG  0x50
#define RDATA 0x01


void setup()
{
  Serial.begin(2000000);

  pinMode(MISO, INPUT);
  pinMode(MOSI, OUTPUT);
  pinMode(SCK, OUTPUT);
  pinMode(CS, OUTPUT);
  SPI.begin(SCK, MISO, MOSI, CS); //start the spi-bus
  delay(1); // LOW at least 4 clock cycles of onboard clock. 100 microsecons is enough

  pinMode(DRDY, INPUT);

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

  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
  //  Reset to Power-Up Values (FEh)
  SPI.transfer(0xFE);
  delayMicroseconds(100);

  //PGA SETTING
  //1 ±5V
  //2 ±2.5V
  //4 ±1.25V
  //8 ±0.625V
  //16 ±312.5mV
  //32 ±156.25mV
  //64 ±78.125mV

  byte status_reg = 0x00;  // address (datasheet p. 30)
  byte status_data = 0B0000001;
  //000 0 0 0 1
  //000 - Factory programmed Identification Bits
  //0 - set MSB transfer
  //0 - Auto-Calibration Disabled
  //0 - Buffer Disabled
  //1 - duplicates state of DRDY pin
  SPI.transfer(WREG | 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 = 0x02; //A/D Control Register (Address 02h)
  byte adcon_data = 0B00000000;
  // 0 00 00 000
  // 0 reserved always 0
  // 00 - Clock Out off
  // 00 - Sensor Detec off
  // 000 - PGA gain = 1
  SPI.transfer(WREG | adcon_reg);
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(adcon_data);   // write the databyte to the register
  delayMicroseconds(10);



  byte drate_reg = 3; //data rate register address: 0x3h
  byte drate_data = 0B00000011;
  // 11110000
  //set data rate to max. (30000 SPS)
  SPI.transfer(WREG | drate_reg);
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(drate_data);   // write the databyte to the register
  delayMicroseconds(10);



  byte mux_reg = 0x01; //Mux Register (Address 01h)
  byte mux_data = 0B00001111;
  // 0000 1111
  // 0000 - AIN0 (default)
  // 1111 - AINCOM
  SPI.transfer(WREG | mux_reg); // MUX register
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(mux_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.endTransaction();

  Serial.println("configured, starting");
}


void loop()
{
  unsigned long adc_val = 0; // store reading

  while (digitalRead(DRDY)) {} ;

  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
  SPI.transfer(RDATA); // Read Data 0000  0001 (01h)
  // delayMicroseconds(10);

  adc_val = SPI.transfer(0xff);  //0xff is a dummy
  adc_val |= (uint32_t)SPI.transfer(0xff) << 8;
  adc_val |= (uint32_t)SPI.transfer(0xff) << 16;
  adc_val |= (uint32_t)SPI.transfer(0xff) << 24;
  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.println(adc_val);
}


And the schematic that I use for ADS1255
ADS1255-schematic (https://ibb.co/gwwAzH)
(https://ibb.co/gwwAzH)
Title: Re: Problem with ADS1256 board
Post by: hgpt on Apr 25, 2018, 03:45 pm
Taking a closer look at the datasheet (http://www.ti.com/lit/ds/symlink/ads1255.pdf) (pg.34) it appears that reading data (in normal reading mode, NOT continuous) requires a settling time t6, hence the " delayMicroseconds(10);" in the original code.

Since I'm after the full 30kSPS data rate, I had to switch to continuous data read mode. using the RDATAC data.(pg.35)
Doing so results in a much higher sample rate that using the first method (posted by dariosalvi). However, once every few samples I get something like a glitch. The output jumps a lot from the normal value.
Code: [Select]

3313369
3314035
3312667
3313295
3312179
3312508
3312664
3312524
3311696
3311673
3312522
3313006
3313290
3289740
3310820
3311046
7762803
3313255
3312941
7829987
3311065
3311739
3311361
3312014
3312525
3312074
3312182
3313031
3310790
3313129
3313799
3310754
3311421
3289738
3311678
3312615
7697909
3312487
3312331
7632141
3313081


As you can see there are some samples of around ~7600000 that shouldn't be there.
Any idea why?

The code I use is the following (ignore the op-amp setup in the first part of setup() )
Code: [Select]


#include <AD8555.h>
#include <SPI.h>

#define SCK   14
#define MOSI  12
#define MISO  27
#define DRDY  26
#define CS 5

#define SPISPEED 1900000
// 1700000

unsigned long adc_val = 0; // store reading

int outpin = 19;
AD8555 opamp(outpin);

void setup()
{
  Serial.begin(2000000);

  //Start----------------Op-Amp setup--------------------

  // get Second Stage Gain code

  Serial.println("Input Second Stage Gain code (0..7)");
  // wait for user to enter value
  while (!Serial.available());

  // set Second Stage Gain code
  if (!opamp.setSecondStageGain(Serial.parseInt())) {
    // opamp will return false if code is out of range
    Serial.println("Invalid Second Stage Gain code. Valid range is 0..7");
    return;
  }


  // First Stage Gain code
  Serial.println("Input First Stage Gain code (0..127)");
  while (!Serial.available());

  if (!opamp.setFirstStageGain(Serial.parseInt())) {
    Serial.println("Invalid First Stage Gain code. Valid range is 0..127");
    return;
  }


  // Offset code
  Serial.println("Input Offset code (0..255)");
  while (!Serial.available());
  if (!opamp.setOffset(Serial.parseInt())) {
    Serial.println("Invalid Offset code. Valid range is 0..255");
    return;
  }

  // Programming mode
  Serial.println("Choose programming mode: Enter \"0\" for simulation, \"1\" for permanent programming");

  while (!Serial.available());
  int mode = Serial.parseInt();
  if (mode == 0) {
    // simulation mode
    opamp.simulate();
    Serial.println("Done!");
  } else if (mode == 1) {
    // permanent programming mode
    Serial.println("Make sure to meet programming requirements described in AD8555 datasheet:");
    Serial.println("- A 5.5 V supply is required");
    Serial.println("- The power supply must be able to deliver 250 mA of current");
    Serial.println("- At least 0.1 uF of decoupling capacitance is needed across the power pins of the device");

    Serial.println("\nWARNING: This operation can not be undone, all programming values are permanent");
    Serial.println("Continue? [y/N]");

    while (!Serial.available());
    if (Serial.read() == 'y') {
      opamp.program();
      Serial.println("Programming... done");
    } else {
      Serial.println("Operation canceled");
    }
  }

  //Finish----------------Op-Amp setup--------------------


  pinMode(MISO, INPUT);
  pinMode(MOSI, OUTPUT);
  pinMode(SCK, OUTPUT);
  pinMode(CS, OUTPUT);
  delay(1); // LOW at least 4 clock cycles of onboard clock. 100 microsecons is enough

  pinMode(DRDY, INPUT);
  delay(500);
  SPI.begin(SCK, MISO, MOSI, CS); //start the spi-bus
  delay(500);

  //init

  // digitalWrite(cs, LOW);
  while (digitalRead(DRDY)) {}  // 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);

  SPI.endTransaction();

  while (digitalRead(DRDY)) {}  // wait for ready_line to go low
  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI

  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
  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);

  byte channel = 0;
  byte data = (channel << 4) | (1 << 3); //AIN-channel and AINCOM
  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.endTransaction();

  while (digitalRead(DRDY)) {}  // wait for ready_line to go low
  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
  
  SPI.transfer(0x03); // Read Data Continuous command 0000  0011 (03h)
  delayMicroseconds(10);
  
  SPI.endTransaction();


  Serial.println("configured, starting");
}


void loop()
{
  //The most efficient way to cycle through the inputs is to
  //change the multiplexer setting (using a WREG command
  //to the multiplexer register MUX) immediately after DRDY
  //goes low. Then, after changing the multiplexer, restart the
  //conversion process by issuing the SYNC and WAKEUP
  //commands, and retrieve the data with the RDATA
  //command.
  
  while (digitalRead(DRDY)) {} ;
  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_MODE1)); // start SPI
  //while (millis() - start_time < 1000) {
  adc_val = SPI.transfer(0);
  adc_val <<= 8; //shift to left
  adc_val |= SPI.transfer(0);
  adc_val <<= 8;
  adc_val |= SPI.transfer(0);
  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.println(adc_val);
}

Title: Re: Problem with ADS1256 board
Post by: hgpt on Jun 27, 2018, 01:36 pm
Could someone please explain to me what am I missing when setting up the registers of an ADS1255 ADC?
The setup fails every time. When I read back from the registers (after setting the up) I get back a totally different value from the one that I set up.

Code: [Select]

STATUS register values:
Received: 11111111

ADCON register values:
Expected: 0
Received: 11111111

DRATE register values:
Expected: 11110000
Received: 11111111

MUX register values:
Expected: 1111
Received: 11111111


Code belllow:

Code: [Select]

#include <SPI.h>

//ADC hook-up lines
#define SCK   14
#define MOSI  12
#define MISO  27
#define DRDY  26
#define CS 5

//SPI bus settings
#define SPISPEED 1800000
#define CLKIN 7680000 //7.68MHz (external crystal frequency)

//ADC commands
#define WREG    0x50
#define RDATA   0x01
#define RDATAC  0x03
#define RREG    0x10
#define SDATAC  0x0F

//enable stuff
#define ENABLE_VERBOSE_OUTPUT 1

/*
   According to datasheet pg.26
   ---------------------------------
   The data input pin (DIN) is used along with SCLK to send
   data to the ADS1255/6. The data output pin (DOUT) along
   with SCLK is used to read data from the ADS1255/6.
   Data on DIN is shifted into the part on the falling edge of SCLK
   while data is shifted out on DOUT on the rising edge of SCLK.
   DOUT is high impedance when not in use to allow
   DIN and DOUT to be connected together and be driven by
   a bi-directional bus. Note: the RDATAC command must
   not be issued while DIN and DOUT are connected
   together.
*/
#define SPI_DATAIN_MODE SPI_MODE0 //DIN shifted out on the falling edge of SCLK
#define SPI_DATAOUT_MODE   SPI_MODE1 //DOUT shifted out on the rising edge of SCLK

//ADC related
signed long raw;
byte adcData[3];
bool ok = false;
byte register_values;

//according to datasheet of ADC pg.6 t6 should be at leas 50 time CLKIN (master clock) period
int t6 = round((float)1 / CLKIN * 50 * 1000000) + 1; //*1000000 to convert from seconds to us

void setup() {
  Serial.begin(2000000);

  //SPI pins
  pinMode(MISO, INPUT);
  pinMode(MOSI, OUTPUT);
  pinMode(SCK, OUTPUT);
  pinMode(CS, OUTPUT);
  pinMode(DRDY, INPUT);

  //init SPI bus
  delay(500);
  SPI.begin(SCK, MISO, MOSI, CS); //start the spi-bus
  delay(500);

  /*
     ADC setup
  */
  while (digitalRead(DRDY)) {}  // wait for ready_line to go low

  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAIN_MODE)); //force proper SPI settings

  //Reset to Power-Up Values (FEh)
  SPI.transfer(0xFE);
  SPI.endTransaction();
  delayMicroseconds(100);

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

  statusRegister_setup();
  adconRegister_setup();
  drateRegister_setup();
  muxRegister_setup();
 
  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAIN_MODE)); //force proper SPI settings
 
  //SYNC command 1111 1100
  SPI.transfer(0xFC);
  delayMicroseconds(10);
 
  //WAKEUP 0000 0000
  SPI.transfer(0x00);
  delayMicroseconds(10);

  SPI.endTransaction();

}

void loop() {
  // put your main code here, to run repeatedly:

}
void muxRegister_setup() {
  /*
     MUX REGISTER SETUP
  */
  byte mux_reg = 0x01; //Mux Register (Address 01h)

  byte mux_data = 0B00001111;
  //chose the 2 inputs for your differential signal
  // 0000 1111
  // 0000 - AIN0 (default)
  // 1111 - AINCOM

  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAIN_MODE)); //force proper SPI settings
  SPI.transfer(WREG | mux_reg); // MUX register
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(mux_data);   // write the databyte to the register
  SPI.endTransaction();

  delayMicroseconds(10); //allow a delay between DIN and DOUT section


  if (ENABLE_VERBOSE_OUTPUT) {
    Serial.println("\nMUX register values: ");

    register_values = 0;
    SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAIN_MODE)); //force proper SPI settings
    SPI.transfer(RREG | mux_reg);
    SPI.transfer(0x00);   // 2nd command byte, read one register only
    SPI.endTransaction();

    delayMicroseconds(t6); // a delay of t6 must occur between RREG and data shifted out

    SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAOUT_MODE));
    register_values = SPI.transfer(0);
    SPI.endTransaction();

    Serial.print("Expected: ");
    Serial.println(mux_data, BIN);
    Serial.print("Received: ");
    Serial.println(register_values, BIN);
  }
}
void drateRegister_setup() {
  /*
     DRATE REGISTER SETUP
  */
  byte drate_reg = 0x03; //data rate register address: 0x03

  byte maxSampleRate = 0B11110000;
  //set data rate to max. (30000 SPS)
  byte minSampleRate = 0B00000011;
  //set data rate to min. (2.5SPS SPS)

  byte chosenRate = maxSampleRate;

  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAIN_MODE)); //force proper SPI settings
  SPI.transfer(WREG | drate_reg);
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(chosenRate);   // write the databyte to the register
  SPI.endTransaction();

  delayMicroseconds(10); //allow a delay between DIN and DOUT section


  if (ENABLE_VERBOSE_OUTPUT) {
    Serial.println("\nDRATE register values: ");

    register_values = 0;
    SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAIN_MODE)); //force proper SPI settings
    SPI.transfer(RREG | drate_reg);
    SPI.transfer(0x00);   // 2nd command byte, read one register only
    SPI.endTransaction();

    delayMicroseconds(t6); // a delay of t6 must occur between RREG and data shifted out

    SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAOUT_MODE));
    register_values = SPI.transfer(0);
    SPI.endTransaction();

    Serial.print("Expected: ");
    Serial.println(chosenRate, BIN);
    Serial.print("Received: ");
    Serial.println(register_values, BIN);
  }
}
void adconRegister_setup() {
  /*
     ADCON REGISTER SETUP
  */
  byte adcon_reg = 0x02; //A/D Control Register address: 0x02

  byte adcon_data = 0B00000000;
  // 0 00 00 000
  // 0 reserved always 0
  // 00 - Clock Out off
  // 00 - Sensor Detec off
  // 000 - PGA gain = 1

  //PGA SETTING
  //1 ±5V
  //2 ±2.5V
  //4 ±1.25V
  //8 ±0.625V
  //16 ±312.5mV
  //32 ±156.25mV
  //64 ±78.125mV

  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAIN_MODE)); //force proper SPI settings
  SPI.transfer(WREG | adcon_reg);
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(adcon_data);   // write the databyte to the register
  SPI.endTransaction();

  delayMicroseconds(10); //allow a delay between DIN and DOUT section


  if (ENABLE_VERBOSE_OUTPUT) {
    Serial.println("\nADCON register values: ");

    register_values = 0;
    SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAIN_MODE)); //force proper SPI settings
    SPI.transfer(RREG | adcon_reg);
    SPI.transfer(0x00);   // 2nd command byte, read one register only
    SPI.endTransaction();

    delayMicroseconds(t6); // a delay of t6 must occur between RREG and data shifted out

    SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAOUT_MODE));
    register_values = SPI.transfer(0);
    SPI.endTransaction();

    Serial.print("Expected: ");
    Serial.println(adcon_data, BIN);
    Serial.print("Received: ");
    Serial.println(register_values, BIN);
  }
}
void statusRegister_setup() {
  /*
     STATUS REGISTER SETUP
  */
  byte status_reg = 0x00;  // address of status reg (datasheet p. 30)

  byte status_data = 0B0000001;
  //000 0 0 0 1
  //000 - Factory programmed Identification Bits
  //0 - set MSB transfer
  //0 - Auto-Calibration Disabled
  //0 - Buffer Disabled
  //1 - duplicates state of DRDY pin

  SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAIN_MODE)); //force proper SPI settings
  SPI.transfer(WREG | status_reg);
  SPI.transfer(0x00);   // 2nd command byte, write one register only
  SPI.transfer(status_data);   // write the databyte to the register
  SPI.endTransaction();

  delayMicroseconds(10); //allow a delay between DIN and DOUT section

  if (ENABLE_VERBOSE_OUTPUT) {
    Serial.println("\nSTATUS register values: ");

    register_values = 0;
    SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAIN_MODE)); //force proper SPI settings
    SPI.transfer(RREG | status_reg);
    SPI.transfer(0x00);   // 2nd command byte, read one register only
    SPI.endTransaction();

    delayMicroseconds(t6); // a delay of t6 must occur between RREG and data shifted out

    SPI.beginTransaction(SPISettings(SPISPEED, MSBFIRST, SPI_DATAOUT_MODE));
    register_values = SPI.transfer(0);
    SPI.endTransaction();

    Serial.print("Received: ");
    Serial.println(register_values, BIN);
  }
}
Title: Re: Problem with ADS1256 board
Post by: Moder10 on Jan 17, 2019, 01:34 pm
Hello,

i got out only zero and i check all input on ADS1256
and i have error if i have on this line  SPI.begin(SCK, MISO, MOSI, CS); //start the spi-bus

and where to connect Reset and PDWN pin?

Greatings Matej
Title: Re: Problem with ADS1256 board
Post by: medboumehraz on Mar 13, 2019, 07:29 pm
Hello,

i got out only zero and i check all input on ADS1256
and i have error if i have on this line  SPI.begin(SCK, MISO, MOSI, CS); //start the spi-bus

and where to connect Reset and PDWN pin?

Greatings Matej
Reset  can be connected to pin 8 or HIGH(3.3 V)  and PDWN to HIGH(3.3 V)