This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS124S08: ADS124S08

Part Number: ADS124S08

Hey 

I am trying to use ADS124s08 to read the voltage of a battery 

AVDD = 5V

DVDD = 3.3V 

I am trying to check the SPI communication from microcontroller to the ADC 

Am writing 04h register with the data 18h using WREG command and trying to read it back using RREG command. But when I use the RREG command and transfer NOPs to get the register value, nothing is reflected on the MISO line. Instead, even the NOP (00h) is getting reflected on MOSI line 

Could you please help me resolving this? 

I have attached the code as well as the logic analyzer file 

#include <SPI.h>

int cs = 10;
int miso = 12;
int mosi = 11;
int sclk = 13;

uint8_t dummy;
int i;
uint8_t ulDataTx[3];
uint8_t ulDataRx[3];

SPISettings mySPISettings(4000000, MSBFIRST, SPI_MODE1);

void setup() {
// put your setup code here, to run once:
pinMode(sclk, OUTPUT);
pinMode(mosi, OUTPUT);
pinMode(miso, INPUT);
pinMode(cs, OUTPUT);
SPI.begin();
SPI.beginTransaction(mySPISettings);
digitalWrite(cs, LOW);
delay(10);
SPI.transfer(0x06); // Reset command
delay(10);
digitalWrite(cs, HIGH);
SPI.endTransaction();
Serial.begin(9600);

delay(1000);


}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(cs, LOW);
delay(10);
SPI.begin();

SPI.beginTransaction(mySPISettings);

//delay(10);

//SPI.transfer(0x06);

//delay(10);

//SPI.endTransaction();


//SPI.beginTransaction(mySPISettings);
delay(10);
//SPI.transfer(0xAA);
//delay(10);
//SPI.transfer(0x55);
//delay(10);
//dummy = SPI.transfer(0x00);
uint8_t ulDataTx[3];
ulDataTx[0] = 0x40 + (0x04 & 0x1f); //WREG command for 04h
ulDataTx[1] = 0x00;
ulDataTx[2] = 0x18;
//selectDeviceCSLow();
SPI.transfer(ulDataTx[0]);
delayMicroseconds(100);
SPI.transfer(ulDataTx[1]);
delayMicroseconds(100);
SPI.transfer(ulDataTx[2]);
//releaseChipSelect();
delay(10);
//SPI.endTransaction();
//digitalWrite(cs, HIGH);
//delay(10);

byte temp2;
byte temp1;
byte temp0;
Serial.println(temp2);
Serial.println(temp1);
Serial.println(temp0);
//SPI.beginTransaction(mySPISettings);
// take the CS low to select the device:
//digitalWrite(cs, LOW);
delay(10);
// send the device the READ comand to start reading:
SPI.transfer(0x24); //RREG command for 04h
SPI.transfer(0x00);
temp1 = SPI.transfer(0x00);
Serial.println(temp1, HEX);
//temp0 = SPI.transfer(0x00);
delay(10);
digitalWrite(cs, HIGH);
delay(10);
SPI.endTransaction();

}

  • Hi Amogh,

    The logic analyzer shots are very helpful as is the code, but can you also send me your schematic?  There are a few considerations:

    • Make sure that the RESET pin is pulled high.
    • Make sure that all supply pins are properly connected and are at the nominal operating voltage before attempting to communicate.  In other words the AVDD/AVSS supply must be active as well as the DVDD and IOVDD supplies.  If one of the supplies is missing, the ADS124S08 will be held in a reset state until all supplies are active.
    • Simplify the communication as much as possible until you have success.  For example, do not send the RESET command and instead try reading a register first before attempting to write a register.  For example, read register 0 (ID) or register 1 (STATUS) which should have non-zero settings following device power-up.
    • Verify that MOSI is connected to the DIN pin on the ADS124S08 and DOUT/DRDY is connected to MISO.
    • If at all possible, use CS to make sure that the framing stays consistent and no extraneous SCLKs are possibly affecting the outcome.  In your loop() function you are pulling CS low and then setting up the SPI parameters.  It is possible a glitch on the SCLK could be taking place.  Also you should not need to setup the SPI in both the setup and loop functions.  So pull CS high after a read/write and set low again prior to a read/write.

    Best regards,

    Bob B

  • Hi Bob, 

    Thanks for the suggestions. I have implemented all of them.

    Now I am able to write to a register and read back the values from them. But I am facing an issue in retrieving the conversion data from using RDATA command. 

    I have attached the schematic, code and snips of the logic analyzer. Kindly help me in resolving this issue 

    Code: 

    #include <SPI.h>

    int cs = 10;
    int miso = 12;
    int mosi = 11;
    int sclk = 13;

    uint8_t dummy, temp1;
    uint8_t i;
    uint8_t ulDataTx[3];
    uint8_t ulDataRx[3];

    SPISettings mySPISettings(4000000, MSBFIRST, SPI_MODE1);

    void setup() {
    // put your setup code here, to run once:
    pinMode(sclk, OUTPUT);
    pinMode(mosi, OUTPUT);
    pinMode(miso, INPUT);
    pinMode(cs, OUTPUT);
    SPI.begin();
    SPI.beginTransaction(mySPISettings);

    Serial.begin(9600);

    writeReg(0x01, 0x80);
    delay(10);
    writeReg(0x02, 0x01);
    delay(10);
    writeReg(0x03, 0x00);
    delay(10);
    writeReg(0x04, 0x5D);
    delay(10);
    writeReg(0x05, 0x10);

    delay(1000);


    }

    void loop() {

    /*writeReg(0x01, 0x80);
    delay(10);
    writeReg(0x02, 0x01);
    delay(10);
    writeReg(0x03, 0x00);
    delay(10);
    writeReg(0x04, 0x5D);
    delay(10);
    writeReg(0x05, 0x10);*/



    /*delay(10);
    uint8_t ManC0 = readReg(0x00);
    Serial.print("0th Val ");
    Serial.println(ManC0, HEX);
    delay(1);

    uint8_t val = readReg(0x05);
    Serial.print("5th Val ");
    Serial.println(val, HEX);
    delay(1);

    uint8_t ManC = readReg(0x01);
    //Serial.println("The value is", ManC);
    Serial.print("1st Val ");
    Serial.println(ManC, HEX);
    delay(1);

    uint8_t ManC1 = readReg(0x02);
    //Serial.println("The value is", ManC1);
    Serial.print("2nd Val ");
    Serial.println(ManC1, HEX);
    delay(1);

    uint8_t ManC2 = readReg(0x03);
    //Serial.println("The value is", ManC2);
    Serial.print("3rd Val ");
    Serial.println(ManC2, HEX);
    delay(1);

    uint8_t ManC3 = readReg(0x04);
    //Serial.println("The value is", ManC3);
    Serial.print("4th Val ");
    Serial.println(ManC3, HEX);
    delay(1);*/

    /*for(i=0x00; i<=0x0B; i++)
    {
    Serial.println(readReg(i),HEX);
    Serial.println("");
    }*/

    readData1();

    }

    uint8_t readReg(uint8_t reg)
    {
    digitalWrite(cs, LOW);
    delay(10);

    uint8_t number = 0x20 + reg;
    SPI.transfer(number);
    SPI.transfer(0x00);
    temp1 = SPI.transfer(0x00);

    delay(10);
    digitalWrite(cs, HIGH);
    delay(10);

    return(temp1);
    }

    void writeReg(uint8_t regnum, uint8_t data)
    {
    digitalWrite(cs, LOW);
    delay(10);

    uint8_t ulDataTx[3];
    ulDataTx[0] = 0x40 + (regnum & 0x1f);
    ulDataTx[1] = 0x00;
    ulDataTx[2] = data;

    SPI.transfer(ulDataTx[0]);

    SPI.transfer(ulDataTx[1]);

    SPI.transfer(ulDataTx[2]);

    delay(10);
    digitalWrite(cs, HIGH);

    delay(10);
    }

    void readData1( )
    {
    byte tempa;
    byte tempb;
    byte tempc;
    //Serial.println(temp2);
    //Serial.println(temp1);
    //Serial.println(temp0);
    //SPI.beginTransaction(SPISettings(SPEED, MSBFIRST, SPI_MODE1));
    // take the CS low to select the device:
    digitalWrite(cs, LOW);
    delay(10);
    // send the device the READ comand to start reading:
    SPI.transfer(0x12);
    tempc = SPI.transfer(0x00);
    //delayMicroseconds(10);
    tempb = SPI.transfer(0x00);
    //delayMicroseconds(10);
    tempa = SPI.transfer(0x00);
    delay(10);
    digitalWrite(cs, HIGH);
    delay(10);
    //SPI.endTransaction();
    Serial.println("After trans");
    Serial.println(tempc);
    Serial.println(tempb);
    Serial.println(tempa);
    byte result = ((tempc<<16)|(tempb<<8)|(tempa));
    Serial.print("Result : ");
    Serial.println(result, HEX);
    }

  • Hi Amogh,

    I see a couple issues with the schematic.  One is that the START/SYNC pin is floating.  This pin when low uses the device commands to start and stop conversions.  When the pin is high, the ADC will always be in conversion mode.  I would suggest tying this pin to ground for now.

    The biggest issue I see and the one that is most likely causing issues is in how the CLK pin is connected.  The CLK pin is the master clock pin for the device and requires a continuous clock.  Currently this pin is connected to SCLK which is intermittent and at the wrong frequency.  Set this pin to ground so that the internal oscillator will start and become the master clock for the ADC.

    Best regards,

    Bob B

  • Hi Bob,

    Thank you for the suggestions. I made the necessary changes in the schematic as suggested by you. I see data on the serial monitor when RDATA command is used. But when both the AIN0 and AINCOM pins are grounded,  values like 941EB (which are random) are appearing, and when a 1.5V battery is connected between AIN0 and AINCOM, 7FFFFF is generated. What could be the possible error? 

    Please help me in resolving this 

    Code: 

    #include <SPI.h>

    int cs = 10;
    int miso = 12;
    int mosi = 11;
    int sclk = 13;

    uint8_t dummy, temp1;
    uint8_t i;
    uint8_t ulDataTx[3];
    uint8_t ulDataRx[3];

    SPISettings mySPISettings(4000000, MSBFIRST, SPI_MODE1);

    void setup() {
    // put your setup code here, to run once:
    pinMode(sclk, OUTPUT);
    pinMode(mosi, OUTPUT);
    pinMode(miso, INPUT);
    pinMode(cs, OUTPUT);
    SPI.begin();
    SPI.beginTransaction(mySPISettings);

    Serial.begin(9600);

    writeReg(0x01, 0x00);
    delay(10);
    writeReg(0x02, 0x0C);
    delay(10);
    /*writeReg(0x03, 0x00);
    delay(10);
    writeReg(0x04, 0x5D);
    delay(10);*/
    writeReg(0x05, 0x0A);

    delay(1000);

    digitalWrite(cs, LOW);
    delay(10);
    SPI.transfer(0x08);
    delay(10);
    digitalWrite(cs, HIGH);

    }

    void loop() {

    for(i=0x00; i<=0x07; i++)
    {
    Serial.println(readReg(i),HEX);
    Serial.println("");
    }

    readData1();

    }

    uint8_t readReg(uint8_t reg)
    {
    digitalWrite(cs, LOW);
    delay(10);

    uint8_t number = 0x20 + reg;
    SPI.transfer(number);
    SPI.transfer(0x00);
    temp1 = SPI.transfer(0x00);

    delay(10);
    digitalWrite(cs, HIGH);
    delay(10);

    return(temp1);
    }

    void writeReg(uint8_t regnum, uint8_t data)
    {
    digitalWrite(cs, LOW);
    delay(10);

    uint8_t ulDataTx[3];
    ulDataTx[0] = 0x40 + (regnum & 0x1f);
    ulDataTx[1] = 0x00;
    ulDataTx[2] = data;

    SPI.transfer(ulDataTx[0]);

    SPI.transfer(ulDataTx[1]);

    SPI.transfer(ulDataTx[2]);

    delay(10);
    digitalWrite(cs, HIGH);

    delay(10);
    }

    void readData1( )
    {
    byte tempa;
    byte tempb;
    byte tempc, tempd, tempe;
    //Serial.println(temp2);
    //Serial.println(temp1);
    //Serial.println(temp0);
    //SPI.beginTransaction(SPISettings(SPEED, MSBFIRST, SPI_MODE1));
    // take the CS low to select the device:
    digitalWrite(cs, LOW);
    delay(10);
    // send the device the READ comand to start reading:
    SPI.transfer(0x13);
    tempc = SPI.transfer(0xff);
    //delayMicroseconds(10);
    tempb = SPI.transfer(0xff);
    //delayMicroseconds(10);
    tempa = SPI.transfer(0xff);
    tempd = SPI.transfer(0xff);
    tempe = SPI.transfer(0xff);
    delay(10);
    digitalWrite(cs, HIGH);
    delay(10);
    //SPI.endTransaction();
    Serial.println("After trans");
    Serial.println(tempc, HEX);
    Serial.println(tempb, HEX);
    Serial.println(tempa, HEX);
    word result = ((tempc<<16)|(tempb<<8)|(tempa));
    Serial.print("Result : ");
    Serial.println(result, HEX);
    }

  • Hi Amogh,

    Can you resend me your corrected schematic so that I can verify all the required changes were made?  Also, if you use the internal reference you must have a cap between REFOUT and REFCOM or the reference will not be stable.

    Have you verified that your register writes are valid by reading back the register data?  Also in register 4, do not write the setting for using the external clock so use the default setting here.

    When collecting data, the NOP command is 0x00 and not 0xFF.  Can you send me the Saleae plots of the communication?

    Best regards,

    Bob B