Hey ,
I am programming an SPI communication between my AD7921 and the microcontroller Arduino DUE.
the Datasheet of my ADC is :http://www.analog.com/static/imported-files/data_sheets/AD7911_7921.pdf
here is the Programm i wrote for both channels. but there is a mistake, that i cant see:
#include <SPI.h>
int cs = 4;
void setup(){
pinMode(cs, OUTPUT);
digitalWrite(cs, HIGH);
SPI.begin();
SPI.setDataMode(SPI_MODE3);
SPI.setClockDivider(cs,21);
SPI.setBitOrder(MSBFIRST);
Serial.begin(9600);
}
void loop()
{
int adcWert0 = readAdc(0);
int adcWert1 = readAdc(1);
delay(1000);
}
int readAdc(int channel)
{
byte adcPrimaryByteMask=00101111;
byte adcPrimaryRegister=channel<<5;
digitalWrite(cs, LOW);
byte adcPrimarybyte = SPI.transfer(adcPrimaryRegister);
byte adcSecondarybyte = SPI.transfer(0x00);
digitalWrite(cs, HIGH);
adcPrimarybyte &= adcPrimaryByteMask;
adcPrimarybyte = adcPrimarybyte << 8;
int adcValue = adcPrimarybyte|adcSecondarybyte;
return adcValue;
}
in Attachements you can see the result of the conversion. it is working only for channel 0.
please i Need you help.