Problem interfacing LTC1857 with Arduino Mega 2560, SPI communication

I am using a LTC1857, 12 bit ADC with Arduino Mega 2560.
here is the link for LTC1857 datasheet: http://cds.linear.com/docs/en/datasheet/185789fa.pdf

page 14 of the datasheet gives the operating sequence of the LTC

Here is my pin diagram

I have connected OVdd, DVdd, AVdd, all these three pins to a same 5V line which is taken from Arduino Mega. I have used 10uF and 0.1uF capacitors at all these lines.

I am trying to start a SPI communication with this chip. I have applied 3.3 V at the input(channel 0). This 3.3V is also taken from arduino.

Here is my code

#include "SPI.h" // necessary library
byte x=0; byte y=0;
word data=0;
void setup()
{
 //set pin(s) to input and output
 pinMode(53, OUTPUT); // pin for SS or CONVST in LTC1857
 pinMode(42, INPUT);  // input pin for BUSY output from LTC1857
 SPI.begin(); // wake up the SPI bus.
 SPI.setBitOrder(MSBFIRST);
 SPI.setDataMode(SPI_MODE0);
}
void loop() 
{
 digitalWrite(53, LOW);  //setting CONVST high to start conversion
 SPI.transfer(140);      // transferring 10001100 bits to ADC.(single ended input at channel 0, 0-10V range, power on.
 delayMicroseconds(1);
 digitalWrite(53, HIGH); // stopping conversion  
 int BUSY=0;
 while(BUSY==0)
   { 
     BUSY=digitalRead(42);    // waiting for BUSY to turn high indication completion of conversion
   }
 x=SPI.transfer(0x00);  // receiving MSB 8 bits
 y=SPI.transfer(0x00);  // receiving next 8 bits
 data=word(x,y);
 Serial.begin(9600); // set up Serial library at 9600 bps
 Serial.print(x,BIN);   // printing results.
 Serial.print("\t");
 Serial.print(y,BIN); 
 Serial.print("\t");
 Serial.print(data,BIN); 
 Serial.print("\n"); 
 delay(10000);
}

And here is how my output looks like for 3.3V, 0-10V range
x y data
1010100 11010000 101010011010000
10010 1100000 1001001100000
10010 1010000 1001001010000
10010 1000000 1001001000000
10010 1100000 1001001100000
10010 1100000 1001001100000
10010 1010000 1001001010000
10010 1100000 1001001100000
10010 1010000 1001001010000
10010 1010000 1001001010000
10010 1100000 1001001100000
10010 1010000 1001001010000
10010 1010000 1001001010000
[/table]

And my output for 5V input at channel 0 only (taken from Arduino), 0-10V
x y data
111110 100000 11111000100000
111110 110000 11111000110000
111110 1010000 11111001010000
111110 1010000 11111001010000
111110 110000 11111000110000
111110 100000 11111000100000
111110 10000 11111000010000
111110 1010000 11111001010000
111110 1100000 11111001100000
111110 100000 11111000100000
111110 1100000 11111001100000
[/table]

now for 3.3V if I ignore the first output which looks garbage, i get 0001 0010 0110 which is 0.7177 V as output.
for 5V i get 0011 1110 0110 which is 2.43V.
Also I am getting the same values of x and y irrespective of the range selected.

So basically I am getting wrong results. Can you please help me understand where I am going wrong?

Hi vik_13, I don't think you have the LTC1857 wired up correctly to the Mega and your code looks a little off as well. Your diagram appears to shows CONVST connected to !BUSY

Serial.begin should be in setup not loop. The way this chip works is you send data on how you want the NEXT conversion to happen while reading results of previous reading at the same time. Your code is sending the data for a single ended channel (0) conversion and only reading half the previous result as you only sent 8 bits. Then you start the conversion and wait for busy to end and then send a differential conversion of channels 0,1 and read the results of previous conversion at same time. The code loops back then to send the half request again.

Riva,

I have not connected CONVST to BUSY. I just noticed there it in the picture. That line is there by mistake.

for the code part I will try to do receive data simultaneously when I send it. like x=SPI.transfer(140); y =SPI.transfer(0); is this what you meant?

vik_13: for the code part I will try to do receive data simultaneously when I send it. like x=SPI.transfer(140); y =SPI.transfer(0); is this what you meant?

Yes that what I mean. Don't forget to move Serial.begin to setup and to be proper your code

  int BUSY=0;
    while(BUSY==0)
   { 
     BUSY=digitalRead(42);    // waiting for BUSY to turn high indication completion of conversion
   }

should be

  int BUSY=LOW;
   while(BUSY==LOW)
   { 
     BUSY=digitalRead(42);    // waiting for BUSY to turn high indication completion of conversion
   }

Thanks. Finally its working now. I tied CONVST and RD together and made the changes you had suggested.

Thanks again for the help.

Hi vik_13,

I'm trying to do something similar to you and need some help figuring out where I went wrong. I'm using an LTC1859 with an Arduino Uno.

I wired everything the same as you except with an Uno. Here are my pins in relation to yours: 53 - 10 (SS) 52 - 13 (SCK) 51 - 12 (MISO) 50 - 11 (MOSI) 42 - 8

I am also trying to start SPI communication with the ADC. I am applying 3.3V to CH0 (input) from the Uno as well and expect to see binary displaying 3.3V - after converting to DEC and dividing by 409.6 (conversion from the datasheet). My results have either been all 1s or all 0s. Is there something I'm missing?

Here is my code based on your code and Riva's inputs:

#include "SPI.h" // necessary library
byte x=0; byte y=0;
word data=0;

void setup()

{
//set pin(s) to input and output
Serial.begin(9600); // set up Serial library at 9600 bps
pinMode(10, OUTPUT); // pin for SS or CONVST in LTC1857
digitalWrite(10, LOW); // initalize pin LOW
pinMode(8, INPUT);  // input pin for BUSY output from LTC1857
SPI.begin(); // wake up the SPI bus.
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE1); // SPI MODE 1 for CPOL=0 where clock is idle at LOW and data capture is on falling edge

}

void loop() 

{

digitalWrite(10, LOW);
delay(1);

SPI.transfer(140); // transferring 10001100 bits to ADC.(single ended input at channel 0, 0-10V range, power on.
delayMicroseconds(1);

digitalWrite(10, HIGH); //setting CONVST high to start conversion
delayMicroseconds(1);

int BUSY=LOW;
while(BUSY==LOW) // wait for busy to go high again
{ 
     BUSY=digitalRead(8); // waiting for BUSY to turn high indication completion of conversion
     delayMicroseconds(1);   
}

digitalWrite(10,LOW);

// read the data
x=SPI.transfer(140); // receiving MSB 8 bits
y=SPI.transfer(0); // receiving next 8 bits
data=word(x,y);
Serial.print(x,BIN); // printing results.
Serial.print("\t");
Serial.print(y,BIN); 
Serial.print("\t");
Serial.print(data,BIN); 
Serial.print("\n"); 
delay(1000);

}