ADS1256 with Arduino Uno

Hello Everyone,

I have interfaced ADS1256 with Arduino Uno. The only doubt is, How do I define the settings for input multiplexer register to perform the single ended meaurements?

As I want to read to data from all 8 channles with single ended measurements. For now I am giving 3.3 volt input to ADC channel to read it as a ADC data but i get only 0 as a ouput in the serial monitor.

If anyone can guide me here it can help me to complete my project.

Thanks Anurag

For now I am giving 3.3 volt input to ADC channel to read it as a ADC data but i get only 0 as a ouput in the serial monitor.

And what code is producing this? Don't forget to use code tags! Provide links to used libraries!

Hello,

This is the library i am using for coding link for the library is given below, it is written for Teensy so i am using the same code for Arduino as same code can be used for the both MCU’s as per my assumptions.

GitHub - mbilsky/TeensyADS1256: Teensy 3.1/3.2 Library for ADS1256 24-Bit ADC.

But this library is written for Differential reading I am trying to modify the same for single ended meaurements.

Here is my code below.

#define   SPI_SPEED     2500000

#define   STATUS        0x00 //Status Control Register 0
#define   MUX           0x01 //Multiplexer Control Register 0
#define   ADCON         0x02 //A/D Control Register 0
#define   DRATE         0x03 //A/D Data Rate Control Register 0

#define   STATUS_RESET  0x01 // Reset STATUS Register

#define   MUX_RESET     0x01      // Reset MUX0 Register
/* PSEL3:0 Positive input channel selection bits */
#define   P_AIN0        B00000000 //(default)
#define   P_AIN1        B00010000
#define   P_AIN2        B00100000
#define   P_AIN3        B00110000
#define   P_AIN4        B01000000
#define   P_AIN5        B01010000
#define   P_AIN6        B01100000
#define   P_AIN7        B01110000
#define   P_AINCOM      B10000000
/* NSEL3:0 Negativ input channel selection bits */
#define   N_AIN0        B00000000
#define   N_AIN1        B00000001 //(default)
#define   N_AIN2        B00000010
#define   N_AIN3        B00000011
#define   N_AIN4        B00000100
#define   N_AIN5        B00000101
#define   N_AIN6        B00000110
#define   N_AIN7        B00000111
#define   N_AINCOM      B00001000


#define   PGA_1 //(default)
#define   PGA_2
#define   PGA_4
#define   PGA_8
#define   PGA_16
#define   PGA_32
#define   PGA_64        B00100111


#define   DRATE_RESET 0xF0 // Reset DRATE Register
/*DR7:0 Data Rate Setting*/
#define   DR_30000      B11110000 //30.000 SPS (default)
#define   DR_15000      B11100000 //15.000 SPS
#define   DR_7500       B11010000 //7.500 SPS
#define   DR_3750       B11000000 //3.750 SPS
#define   DR_2000       B10110000 //2.000 SPS
#define   DR_1000       B10100001 //1.000 SPS
#define   DR_500        B10010010 //500 SPS
#define   DR_100        B10000010 //100 SPS
#define   DR_60         B01110010 //60 SPS
#define   DR_50         B01100011 //50 SPS
#define   DR_30         B01010011 //30 SPS
#define   DR_25         B01000011 //25 SPS
#define   DR_15         B00110011 //15 SPS
#define   DR_10         B00100011 //10 SPS
#define   DR_5          B00010011 //5 SPS
#define   DR2_5         B00000011 //2,5 SPS


#define   WAKEUP        0x00  //Exit Sleep Mode
#define   STANDBY       0xFD  //Enter Sleep Mode
#define   SYNC          0xFC    //Synchornize the A/D Conversion
#define   RESET         0xFE  //Reset To Power UP values
#define   NOP           0xFF  //No operation

#define   RDATA         0x01  //Read data once
#define   RDATAC        0x03  //Read data continously
#define   SDATAC        0x0F  //Stop reading data continously

/*READ REGISTER */
#define   RREG          0x10  //Read From Register
#define   WREG          0x50  //Write To Register
/*Calibration */
#define   SELFCAL       0xF0  //Self Offset Calibration

#include  <SPI.h>
//#include  <digitalWriteFast.h> // for arduino boards

#define   ADS_RST_PIN   8 //ADS1256 reset pin
#define   ADS_RDY_PIN   9 //ADS1256 data ready
#define   ADS_CS_PIN    10 //ADS1256 chip select
/* 
    CLK  - pin 13
    DIN  - pin 11 (MOSI)
    DOUT - pin 12 (MISO)
*/
float   resolution = 8388608.;
float   Gain =       64.; //be sure to have a period 
float   vRef =       5.; //reference voltage
//we'll calculate this in setup
float   bitToVolt  = 0.;

void setup()
{
  delay(1000);
  Serial.begin(115200);

  pinMode(ADS_CS_PIN,  OUTPUT);
  pinMode(ADS_RDY_PIN,  INPUT);
  pinMode(ADS_RST_PIN, OUTPUT);

  SPI.begin();
  initADS();
  Serial.println("booting");
  Serial.println("done init");

  bitToVolt = resolution*Gain/vRef;
}

int32_t val1;
int32_t adc_value;

void loop()
{
double value = 0;
for (int i = 0; i <1; i++)//i<10
{
  value += read_Value();
}

value /= 1.;
value /= bitToVolt;

Serial.println(value,3);

}

void initADS()
{
  attachInterrupt(ADS_RDY_PIN, DRDY_Interuppt, FALLING);

  digitalWrite(ADS_RST_PIN, LOW);
  delay(10); // LOW at least 4 clock cycles of onboard clock. 100 microsecons is enough
  digitalWrite(ADS_RST_PIN, HIGH); // now reset to deafult values

  delay(1000);

  //now reset the ADS
  Reset();
  delay(2000);
  //this enables the buffer which gets us more accurate voltage readings
  SetRegisterValue(STATUS,B00110010);

//  Serial.println(GetRegisterValue(STATUS));
  SetRegisterValue(MUX, B00001000); // MUX_RESET set the mux register
   //B00001000 for single ended measurement
  SetRegisterValue(ADCON, PGA_64); //set the adcon register
  SetRegisterValue(DRATE, DR_30000); //set the drate register
  delay(2000);

  SendCMD(SELFCAL); //send the calibration command
  //then print out the values
  delay(5);
}

int32_t read_Value()
{
  int32_t adc_val;
 // byte    channel = 0;
  
  waitforDRDY(); // Wait until DRDY is LOW
  SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1));
  
  digitalWriteFast(10, LOW); //Pull SS Low to Enable Communications with ADS1247
  delayMicroseconds(5); // RD: Wait 25ns for ADC12xx to get ready

//  byte data = (channel << 4 | 1 << 3)
//  SetRegisterValue(MUX, data);
   
  SPI.transfer(RDATA); //Issue RDATA
  delayMicroseconds(5);
  
  adc_val |= SPI.transfer(NOP);
  //delayMicroseconds(10);
  adc_val <<= 8;
  adc_val |= SPI.transfer(NOP);
  //delayMicroseconds(10);
  adc_val <<= 8;
  adc_val |= SPI.transfer(NOP);
  delayMicroseconds(5);
      
  digitalWriteFast(10, HIGH);
  SPI.endTransaction();

  if (adc_val > 0x7fffff) 
  { //if MSB == 1
    adc_val = adc_val - 16777216; //do 2's complement, keep the sign this time!
  }
//  float voltage = adc_val * (vRef / resolution);
//  return voltage;
  return adc_val;
}

long GetRegisterValue(uint8_t regAdress) 
{
  uint8_t bufr;
  digitalWriteFast(10, LOW);
  delayMicroseconds(10);
  SPI.transfer(RREG | regAdress); // send 1st command byte, address of the register
  SPI.transfer(0x00);     // send 2nd command byte, read only one register
  delayMicroseconds(10);
  bufr = SPI.transfer(NOP); // read data of the register
  delayMicroseconds(10);
  digitalWriteFast(10, HIGH);
  SPI.endTransaction();
  return bufr;

}
void SendCMD(uint8_t cmd) 
{
  waitforDRDY();
  SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with 4Mhz clock, MSB first, SPI Mode0
  digitalWriteFast(10, LOW);
  delayMicroseconds(10);
  SPI.transfer(cmd);
  delayMicroseconds(10);
  digitalWriteFast(10, HIGH);
  SPI.endTransaction();
}

void Reset()
{
  SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with  clock, MSB first, SPI Mode1
  digitalWriteFast(10, LOW);
  delayMicroseconds(10);
  SPI.transfer(RESET); //Reset
  delay(2); //Minimum 0.6ms required for Reset to finish.
  SPI.transfer(SDATAC); //Issue SDATAC
  delayMicroseconds(100);
  digitalWriteFast(10, HIGH);
  SPI.endTransaction();
}

void SetRegisterValue(uint8_t regAdress, uint8_t regValue)
{

  uint8_t regValuePre = GetRegisterValue(regAdress);
  if (regValue != regValuePre)
  {
    delayMicroseconds(10);
    waitforDRDY();
    SPI.beginTransaction(SPISettings(SPI_SPEED, MSBFIRST, SPI_MODE1)); // initialize SPI with SPI_SPEED, MSB first, SPI Mode1
    digitalWriteFast(10, LOW);
    delayMicroseconds(10);
    SPI.transfer(WREG | regAdress); // send 1st command byte, address of the register
    SPI.transfer(0x00);   // send 2nd command byte, write only one register
    SPI.transfer(regValue);         // write data (1 Byte) for the register
    delayMicroseconds(10);
    digitalWriteFast(10, HIGH);

    if (regValue != GetRegisterValue(regAdress))
    {   //Check if write was succesfullvolatile int DRDY_state = HIGH;

      Serial.print("Write to Register 0x");
      Serial.print(regAdress, HEX);
      Serial.println(" failed!");
    }
    else
    {
      Serial.println("success");
    }
    SPI.endTransaction();

  }

}
volatile int DRDY_state = HIGH;

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

//Interrupt function
void DRDY_Interuppt() 
{
  DRDY_state = LOW;
}
  digitalWriteFast(10, LOW); //Pull SS Low to Enable Communications with ADS1247

It's very bad style to define a precompiler constant for the CS line but then using the explicit number in the code!

  delayMicroseconds(5); // RD: Wait 25ns for ADC12xx to get ready

This waits 200 times as long as necessary. Just delete that line the above command will need more than the 25ns to finish.

I would change to this library. It's written for Arduino and it's written as a library. It also avoids the unnecessary delay calls (might be necessary for the much faster Teensies).

Post a wiring diagram of your setup!

i want code work with arduino due i have carde ads1256

Hello guys,

i upload code with out problem, but in in Serial interface i don't get anything not even booting line just program isn't runnig or what, code is the same as in post from anurag2508

any idea what is wrong?

Greatings Matej

any idea what is wrong?

What type of Arduino are you using? An UNO as the OP?