ANALOG TO DIGITAL CONVERTER ADS7816 INTERFACING WITH ARDUINO


PINOUT
CIRCUIT DIAGRAM
PROGRAM

#define CS 10    //Chip selection pin  
#define DATAPIN 12    //Data pin
#define CLOCK 6  //ADS 7817 clock

void setup()
{              
  initspi();
  Serial.begin(9600);  //Initialize serial for debugging
}

void loop()
{
  int a = readADS7817();
 Serial.println(a);
 delay(200);  //Delay between data sampling streams
}

void del1(void)
{
 delayMicroseconds(1);
}

void initspi(void)
{
    pinMode(CS, OUTPUT);  //Set up pin modes
  pinMode(DATAPIN, INPUT);
  pinMode(CLOCK, OUTPUT);
    //Ensure ADS7817 is powered off to start

  digitalWrite(CS, HIGH);  //Pin needs to be high for shutdown mode
  digitalWrite(CLOCK, LOW);
}

int readADS7817()
{
  int adcvalue=0;
  digitalWrite(CS, LOW);  //Select the ADS7817
  //Cycle clock to ignore two null bits of data transferred
     clock ();
     clock ();
  //Read the 12 data bits from ADS 7817
  for (int i=11; i>=0; i--)
  {
     clock ();
    adcvalue+=digitalRead(DATAPIN)<<i;//???
  }
  digitalWrite(CS, HIGH);  //Power down ADS7817
  return adcvalue;
}
void clock (void)
{
   digitalWrite(CLOCK, HIGH);
   digitalWrite(CLOCK, LOW);
}