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.

i have problem in write and read the ads1256

Other Parts Discussed in Thread: ADS1256

hello 

i am trying to interface ads1256 with arduino uno . but i have a problem in that i try to write and read the register.i read 1st four register and print on serialport.

but result is always 

FF

FF

FF

FF

my code is

#include <SPI.h>

#define DRDY_PIN 6

#define CS_PIN 7

#define SPI_MASTER_DUMMY   0xFF

#define MISO_PIN 12

#define MOSI_PIN 11

#define SCK_PIN 13

#define RESET_PIN 22

#define WREG  0x50

//#define RREG  0x23

#define RREG  0x10

#define PGA 1                 // Programmable Gain = 1

#define VREF 5            // Internal reference of 2.048V

#define VFSR VREF/PGA            

#define FSR (((long int)1<<23)-1) 

 

 

 

//const int dataReadyPin = 6;

//const int chipSelectPin = 10;

 

 volatile byte MSB;

 volatile byte data;

 volatile byte LSB;

 uint8_t Config_Reg0;

 uint8_t Config_Reg1;

 uint8_t Config_Reg2;

 uint8_t Config_Reg3;

//volatile char SPI_RX_Buff[3];

  volatile byte *SPI_RX_Buff_Ptr;

 

void setup()

{

 

 void writeRegister(uint8_t address, uint8_t value);

 uint8_t readRegister(uint8_t address);

 Serial.begin(9600);

 SPI.begin();

 pinMode(DRDY_PIN, INPUT);

 pinMode(CS_PIN, OUTPUT);

 digitalWrite(CS_PIN, LOW);

 pinMode(SCK_PIN, OUTPUT);

 digitalWrite(SCK_PIN, LOW);

 

    

 

  writeRegister(0x00, 0x01);/// (REGISTER ADRESS:VALUE)

  writeRegister(0x01, 0x0F);

  writeRegister(0x02, 0x20);

  writeRegister(0x03, 0xF0);

  writeRegister(0x04, 0xE0);

  writeRegister(0x05, 0x00);

  writeRegister(0x06, 0x00);

  writeRegister(0x07, 0x00);

  writeRegister(0x08, 0x08);

  writeRegister(0x09, 0xAC);

  writeRegister(0x0A, 0x44);

 

  Config_Reg0 = readRegister(0x00);

  Config_Reg1 = readRegister(0x01);

  Config_Reg2 = readRegister(0x02);

  Config_Reg3 = readRegister(0x03);

 

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

  digitalWrite(CS_PIN,HIGH); //release chip, signal end transfer

   delay(100);

 

}

 

 

void loop()

{

  long int bit32;

  long int bit24;

  byte *config_reg;

  static byte SPI_Buff[3];

 

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

  {

    digitalWrite(CS_PIN,LOW);                         //Take CS low

    delayMicroseconds(100);

    for (int i = 0; i < 3; i++)

    {

      SPI_Buff[i] = SPI.transfer(SPI_MASTER_DUMMY);

    }

    delayMicroseconds(100);

    digitalWrite(CS_PIN,HIGH);  

    //  Clear CS to high

     MSB = SPI_Buff[0];   

     data = SPI_Buff[1];

     LSB = SPI_Buff[2];

 

  bit24 = MSB;

  bit24 = (bit24 << 8) | data;

  bit24 = (bit24 << 8) | LSB;                                 // Converting 3 bytes to a 24 bit int

   

 

bit24= ( bit24 << 8 );

bit32 = ( bit24 >> 8 );                      // Converting 24 bit two's complement to 32 bit two's complement

 

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

 

  delay(300);

 

 //Serial.print("Vout in mV : ");

  Serial.println(Vout);

  //Serial.print("Vout in V : "); 

// Serial.print(Vout/1000);

//Serial.print("  32bit HEX : ");

//Serial.println(bit32,BIN);

    

      }

     }

 

 

 

 

  void writeRegister(uint8_t address, uint8_t value)

{

  digitalWrite(CS_PIN,LOW);

  delay(5);

  SPI.transfer(WREG|(address<<2));

  SPI.transfer(value);

  delay(5);

  digitalWrite(CS_PIN,HIGH);

}

 

 

 

uint8_t readRegister(uint8_t address)

{

  uint8_t data;

 

  digitalWrite(CS_PIN,LOW);

  delay(5);

  SPI.transfer(RREG|(address<<2));

  data = SPI.transfer(SPI_MASTER_DUMMY);

  delay(5);

  digitalWrite(CS_PIN,HIGH);

 

  return data;

}

i see the output on saleae logic analyzer

please sir i am confused where i do mistake....

thank in advance 

and sorry for my bad english

  • Hi Yatin,

    Welcome to the TI E2E Forums!

    I'm not sure why your data appears as "FF"; that may be a code bug that you'll have to look into such as not properly configuring the SPI peripheral. From the logic analyzer screenshot it looks like you are reading data and none of the data bytes appear to be "FF".

    A couple things I noticed:

    • /CS seems to be going high before finishing the data read back, yet MISO is still toggling. Are you sharing the SPI bus with another device - if so you might check for a bus contention.
    • When sending the READ and WRITE commands, you need to make sure to include the second command byte that tells the ADC how many registers you are reading or writing to:

    I'm not too familiar with the Arduino microcontroller, but you might try referencing the example Arduino code (and Github project) in this related E2E thread:

    Best Regards,
    Chris