ADS1256 - Reading and writing registers

In this video I show you how to read and write the registers of the ADS1256. Everything is explained based on the datasheet of the device and implemented for Arduino. I tested everything before demonstrating it, and everything works fine.



Reading registers

//Datasheet: http://www.ti.com/lit/ds/sbas288k/sbas288k.pdf
//This is just a code snippet for reading registers, not the entire code 
unsigned long readRegister(uint8_t registerAddress) //Function for READING a selected register
{
    waitforDRDY(); //Waiting for DRDY to go low ('1')
    //this is a separate function that watches the attachinterrupt() pin
 
    SPI.beginTransaction(SPISettings(1700000, MSBFIRST, SPI_MODE1));
    //SPI_MODE1 = output edge: rising, data capture: falling; clock polarity: 0, clock phase: 1.
 
    digitalWrite(CS_pin, LOW); //CS must stay LOW during the entire sequence [Ref: P34, T24]
 
    delayMicroseconds(7); //see t6 in the datasheet
    //t6 = 50 * tau_CLKIN = 50 * 130.2 ns = 6510 ns = 6.51 us; you want to round it UP to the next integer (even if it would be 6.1 us)
 
    SPI.transfer(0x10 | registerAddress); //0x10 = RREG, '|' = bitwise OR operation
 
    SPI.transfer(0x00);
 
    delayMicroseconds(7); //see t6 in the datasheet
 
    registerValueR = SPI.transfer(0xFF); //obtaining the data and 'saving' into the variable
 
    delayMicroseconds(7); //see t6 in the datasheet
 
    digitalWrite(CS_pin, HIGH);
 
    SPI.endTransaction();
 
    return registerValueR;
}


Writing registers

//Datasheet: http://www.ti.com/lit/ds/sbas288k/sbas288k.pdf
//This is just a code snippet for reading registers, not the entire code 
 
void writeRegister(uint8_t registerAddress, uint8_t registerValueW)
{
    waitforDRDY(); //waiting for DRDY to go LOW
 
    SPI.beginTransaction(SPISettings(1700000, MSBFIRST, SPI_MODE1));
    //SPI_MODE1 = output edge: rising, data capture: falling; clock polarity: 0, clock phase: 1.
 
    digitalWrite(CS_pin, LOW); //CS must stay LOW during the entire sequence [Ref: P34, T24]
 
    delayMicroseconds(7); //see t6 in the datasheet
    //t6 = 50 * tau_CLKIN = 50 * 130.2 ns = 6510 ns = 6.51 us; you want to round it UP to the next integer (even if it would be 6.1 us)
 
    SPI.transfer(0x50 | registerAddress); // 0x50 = WREG, '|' = Bitwise OR operator
 
    SPI.transfer(0x00);
 
    delayMicroseconds(7); //see t6 in the datasheet
 
    SPI.transfer(registerValueW); //Sending the desired value of the register that we write
    //registerValueW is a variable which gets its value from the serial terminal
 
    delayMicroseconds(7); //see t6 in the datasheet
 
    digitalWrite(CS_pin, HIGH);
 
    SPI.endTransaction();
}

Previous
Previous

ADS1256 - Reading a single conversion result using RDATA

Next
Next

ADS1256 - Registers and demonstration