Hello, I made my Analog to Digital Converter few hours ago. However, it doesn't work. It just print 0 all the time. Please give me any suggestion.
I refered the code from here. " Talking to the ADS7883 with the Arduino Uno - Networking, Protocols, and Devices - Arduino Forum " In there, same IC chip and same content.
Here is my code.
#include <SPI.h>
const byte slaveSelectPin = 10; //CS
void setup() {
Serial.begin(9600);
pinMode(slaveSelectPin,OUTPUT);
digitalWrite(slaveSelectPin,HIGH); //chip active LOW
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE1);
SPI.setClockDivider(SPI_CLOCK_DIV16);
Serial.println("Initialized!");
}
void loop() {
long readADC = SpiRead();
Serial.println(readADC);
}
long SpiRead(void) {
byte result;
byte b;
digitalWrite(slaveSelectPin,LOW);
result = SPI.transfer(0xFF);
result <<= 8;
b = SPI.transfer(0xFF);
result |= b;
result = result>>2;
digitalWrite(slaveSelectPin,HIGH);
return(result);
}