trouble in connecting AD converter (AD7176-2) and arduino

Hi, Arduino Users,

I have a problem to connect Arduino ,AD converter , and accelerometer.
Arduino: Arduino Uno
ADC : AD7176-2
accelerometer: ADXL335

I need a high-precision [24-bit] analog to digital converter (ADC) for my research.
then I looked for some tutorial staffs, and tried a lot,
but still cannot find what problems I have.

Serial.print() writes same number; like

//-------------------//
AD7176-2 Test
0.01, 5000000.00
0.02, 5000000.00
0.03, 5000000.00
0.04, 5000000.00
0.05, 5000000.00

//-------------------//

this is the program what i am using

//////////////////////////////////////////
#include <SPI.h>  // include the SPI library

// set I/O pins used in addition to clock, data in, data out
const byte slaveSelectPin = 10;  // digital pin 10 for /CS
const byte resetPin = 9;  // digital pin 9 for /RESET

const int nsamples = 3;  // how many ADC readings to average together

// SPI_CLOCK_DIV16 gives me a 1.0 MHz SPI clock, with 16 MHz crystal on Arduino

void setup() {
  
    Serial.begin(9600);      // set up serial comm to PC at this baud rate
    
    pinMode (slaveSelectPin, OUTPUT);
    pinMode (resetPin, OUTPUT);
    digitalWrite(slaveSelectPin,HIGH);  // chip select is active low
    digitalWrite(resetPin,HIGH);  // reset is active low

    SPI.begin(); // initialize SPI, covering MOSI,MISO,SCK signals
    SPI.setBitOrder(MSBFIRST);  // data is clocked in MSB first
    SPI.setDataMode(SPI_MODE3);  // SCLK idle low (CPOL=0), MOSI read on rising edge (CPHI=0)
    SPI.setClockDivider(SPI_CLOCK_DIV16);  // system clock = 16 MHz, chip max = 1 MHz
    
    Serial.println("AD7176-2 Test");
}

// =============================================================================
// Main Loop: 
// acquire 'nsamples' readings, convert to units of volts, and send out on serial port

void loop() {

int i;
long secs;
float mins;
double volts;
long in;         // incoming serial 32-bit word
long sum = 0;

    for (i=0; i<nsamples; i++) {
      in = SpiRead();
      in &= 0x1FFFFFFF; // force high three bits to zero
      in = in>>5;   // truncate lowest 5 bits
      sum += in;
      delay(198);      // (msec). Total Looptime: +2 msec (overhead for comms)
    }

    // volts =  in * 2.5 / 8.388607;  // 0x7fffff = 8388607
    volts = sum * (0.2980232594);  // microvolts
    volts = volts / nsamples;

    mins = (float) millis() / 60000;   // elapsed time in minutes
    Serial.print(mins);  
    Serial.print(", ");
    Serial.println(volts);
    Serial.print("\n");
} // end main loop


// =================================================================
// SpiRead() -- read out 4 bytes from LTC2440 chip via SPI interface
// =================================================================

long SpiRead(void) {

  long result = 0;
  long b;
  
//  long result2 = 0;// MOSI/SDI pin 7 HIGH => 7 Hz, best resolution

  digitalWrite(slaveSelectPin,LOW);   // take the SS pin low to select the chip
  delayMicroseconds(1);              // probably not needed, only need 25 nsec delay
  
  b = SPI.transfer(0xff);   // B3
  result = b<<8;          
  b = SPI.transfer(0xff);   // B2
  result |= b;
  result = result<<8;
  b = SPI.transfer(0xff);   // B1
  result |= b;
  result = result<<8;
  b = SPI.transfer(0xff);   // B0
  result |= b;
  
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH);
  return(result);
}

//original program is from
//http://dangerousprototypes.com/forum/viewtopic.php?f=2&t=4247&p=42053#p42051
//adc is different one from mine.

////////////

any help or advice would be appreciated a lot.

sincerely,

Yoshi

Hi Yoshi

You are not sending any configuration commands to the ADC so, from a quick read of the datasheet, it will start up in continuous conversion mode (datasheet p34).

The diagram on that page (Figure 47) suggests you need to send a one byte command (0x44) to the ADC before trying to read the data. See also p17 of the datasheet.

Try adding this at the start of your SpiRead() function ...

digitalWrite(slaveSelectPin,LOW);
delayMicroseconds(1);
SPI.transfer(0x44);
digitalWrite(slaveSelectPin,HIGH);

If that does not work, maybe try something simpler by reading the ID Register (datasheet p18). Send 0x07, read two bytes, expect the result 0x0C9x.

Regards

Ray

Hi Ray,

First, thank you for your reply.

I understood I did not identify what ADC is doing next . then I added this at the beginning of SPI.read();

  digitalWrite(slaveSelectPin,LOW);
  delayMicroseconds(1);
  SPI.transfer(0xA1);// ?100100000?communication register == Channel MAP register1
  
  SPI.transfer(0x00);  //CHANNEL MAP REGISTETR 1  //00000000000000001 for 16bit
  SPI.transfer(0x01);  //positive input == AIN0 & negative input == AIN1
  digitalWrite(slaveSelectPin,HIGH);

but still not work well.

what is the problem??

thank you.

Yoshi

Try just reading the device ID to test that communications is working.

Remove code from your program so that all you have in loop() is something like this ...

void loop()
{
    digitalWrite(slaveSelectPin,LOW);
    delayMicroseconds(1);
    SPI.transfer(0b01000111); // Bit 6 = 1 for read. Register 0x07 for ID register. 
    digitalWrite(slaveSelectPin,HIGH);

    digitalWrite(slaveSelectPin,LOW);
    delayMicroseconds(1);
    byte b1 = SPI.transfer(0xFF);
    byte b0 = SPI.transfer(0xFF);
    digitalWrite(slaveSelectPin,HIGH);
    
    unsigned int result = b1 * 256 + b0;
    Serial.println(result, HEX);

    delay(1000);
}

The result should be 0x0C94.