Hi there,
hope you could help me out.
I've spent the best part of the weekend trying to make this analog-digital-converter talk to my Arduino using SPI but it just won't work.
The datasheet is available for download here:
http://www.analog.com/static/imported-files/data_sheets/AD7788_7789.pdf
I've connected the chip according to the datasheet using the standard SPI ports on the Arduino and started my attempts according to the SPI EEPROM example on arduino.cc. See code for details.
No matter what I do, I keep getting 0xFFFF back from the ADC. If I disconnect the MISO then I can see the signal float, so I guess Arduino is reading properly. If I disconnect the clock signal to the chip then it outputs 0x00 so at least the chip is alive? I've even tried some bit-bang methods omitting Arduino's SPI hardware support but I get the same results.
My below code example should configure the ADC for continuous read mode in setup(), activate the data register and read 2 bytes in loop().
What could I be doing wrong, or could the chip be broken? Even when I read out the status register I only get 0xFFFF back.
Would be fantastic if someone here already has had experiences with this particular ADC. This is really frustrating.
Alternatively I would also be interested if someone has got a 16-Bit ADC working with Arduino and would like to share the details.
Best Regards
Classic
This is the code I am using:
#define MOSI 11//MOSI
#define MISO 12//MISO
#define SCLK 13//sck
#define CS 10//ss
uint16_t adcOut;
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
return SPDR; // return the received byte
}
void setup()
{
Serial.begin(9600);
Serial.println("Start");
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
pinMode(SCLK,OUTPUT);
pinMode(CS,OUTPUT);
digitalWrite(CS,HIGH); //disable device
//interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
//sample on leading edge of clk,system clock/4 rate (fastest)
SPCR = (1<<SPE)|(1<<MSTR);
digitalWrite(CS,LOW); //enable device
// set continuous read mode, does not require subsequent write to communications register anymore
spi_transfer(B00111100);
digitalWrite(CS,HIGH); //disable device
delay(250);
}
void loop()
{
digitalWrite(CS,LOW); //enable device
adcOut |= (spi_transfer(0x00)<<8); // read first byte
adcOut |= spi_transfer(0x00); // read second byte
Serial.println(adcOut,BIN);
digitalWrite(CS,HIGH); //disable device
delay(250);
adcOut = 0; // reset value
}