ADS1256 - Reading a single conversion result using RDATA

In this video I show you how to read a single conversion result from the ADS1256 via SPI communication using an Arduino. I explain a few things in more details such as shifting out the three bytes (MSB, Mid-byte, and LSB) and constructing the 24-bit conversion result. I also talk about the representation of the negative sign and how the conversion result is converted into voltage. In the beginning of the explanation I made a mistake. The writeRegister(0x01, B00101000); is selecting the [AIN2] as the positive input pin. In order to select the [AIN0 + AINCOM] combination, you have to use writeRegister(0x01, B00001000);



RDATA function

//Datasheet: http://www.ti.com/lit/ds/sbas288k/sbas288k.pdf
//This is just a code snippet for the RDATA function, not the entire code 
void readSingle()
{
    //Reading a single conversion value
 
    //First we need to write some registers to select an input:
    //Set up MUX (0x01) and select the input channels [AIN0(+) + COM(-) = 0000 1000]
    writeRegister(0x01, B00001000); //In the video, I accidentally had B00101000 which is the AIN2(+) + AINCOM(-)  
   
    registerData = 0; // every time we call this function, this should be 0 in the beginning!
   
    //Wait for DRDY to go LOW
    waitforDRDY(); 
 
    SPI.beginTransaction(SPISettings(1700000, MSBFIRST, SPI_MODE1));
 
    digitalWrite(CS_pin, LOW); //REF: P34: "CS must stay low during the entire command sequence"
       
    //Issue RDATA (0000 0001) command
    SPI.transfer(B00000001);
 
    //Wait t6 time (~6.51 us) REF: P34, FIG:30.
    delayMicroseconds(7);
 
    //step out the data: <MSB | mid-byte | LSB>
 
    //registerData is ZERO
    registerData |= SPI.transfer(0x0F); //MSB comes in, first 8 bit is updated // '|=' bitwise OR operator
    registerData <<= 8;                 //MSB gets shifted LEFT by 8 bits
    registerData |= SPI.transfer(0x0F); //MSB | Mid-byte
    registerData <<= 8;                 //MSB | Mid-byte gets shifted LEFT by 8 bits
    registerData |= SPI.transfer(0x0F); //(MSB | Mid-byte) | LSB - final result
    //After this, DRDY should go HIGH automatically (see datasheet)    
   
    digitalWrite(CS_pin, HIGH); //We finished the command sequence, so we switch it back to HIGH
    SPI.endTransaction();  
   
    //taking care of the negative numbers (0 to -5V)
    if (long minus = registerData >> 23 == 1) //if the 24th bit (sign) is 1, the number is negative
    {
        registerData = registerData - 16777216;  //conversion for the negative sign
        //"mirroring" around zero
    }
 
    double voltage = (5.0 / 8388608)*registerData; //5.0 = Vref; 8388608 = 2^{23} - 1
 
    //Basically, dividing the positive range with the resolution of it and multiplying with the bits
 
    Serial.println(voltage, 8); //print it on serial, 8 decimals   
 
}

Previous
Previous

ADS1256 - Single-, and multi-channel continuous acquisition

Next
Next

ADS1256 - Reading and writing registers