Using AD7715 ADC

Hi guys,

I have a problem with the communication with the ADC AD7715. Here is my code:

#include <EEPROM.h>

#define CS_ADC 8
#define CS_DAC1 9
#define CS_DAC2 10
#define SCLK 11
#define SDIN 12
#define SDOUT 13
#define DATA_READY 2
#define RESET_ADC 4

int a = 0;
int k = 0;
int value;

void setup() {
  Serial.begin(9600);
  // Set pin modes
  pinMode(CS_ADC,OUTPUT);
  pinMode(CS_DAC1,OUTPUT);
  pinMode(CS_DAC2,OUTPUT);
  pinMode(SCLK,OUTPUT);
  pinMode(SDIN,INPUT);
  pinMode(SDOUT,OUTPUT);
  pinMode(DATA_READY,INPUT);
  pinMode(RESET_ADC,OUTPUT);

  // Set CS_DAC1,CS_DAC2 and SCLK
  digitalWrite(CS_DAC1, HIGH);
  digitalWrite(CS_DAC2, HIGH);
  digitalWrite(CS_ADC, HIGH);
  digitalWrite(SCLK, HIGH);

  // Initialize ADC
  // 1. Communication register
  digitalWrite(CS_ADC, LOW);
  digitalWrite(SCLK, HIGH);
  int comm_reg = 16;
  for(int i = 0; i < 8; i++) {
    digitalWrite(SCLK,LOW);
    unsigned int mask = 1 << (7 - i);
    if (mask & comm_reg) {
      digitalWrite(SDOUT,HIGH);
    }
    else{
      digitalWrite(SDOUT,LOW);
    }
    digitalWrite(SCLK,HIGH);
  }
  digitalWrite(CS_ADC,HIGH);
  digitalWrite(SCLK,HIGH);
 
  // 2. Setup register
  digitalWrite(CS_ADC,LOW);
  int setup_reg = 62;
  for(int j = 0; j < 8; j++) {
    digitalWrite(SCLK,LOW);
    unsigned int mask = 1 << (7 - j);
    if (mask & setup_reg) {
      digitalWrite(SDOUT,HIGH);
    }
    else{
      digitalWrite(SDOUT,LOW);
    }
    digitalWrite(SCLK,HIGH);
  }
  digitalWrite(CS_ADC, HIGH);
  digitalWrite(SCLK, HIGH);
 
}

void loop() {
  // DAC1
  digitalWrite(CS_DAC2, HIGH);
  digitalWrite(CS_DAC1, LOW);

  value = EEPROM.read(a);
  int multiplied_value = value*512;
   
  if(a == 64){
    multiplied_value = 32767;
  }
  for (int i = 0; i < 16; i++) {
    digitalWrite(SCLK, HIGH);
    unsigned int mask = 1 << (15 - i);
           
    if (mask & multiplied_value){
      digitalWrite(SDOUT,HIGH);
      Serial.print(1);
    }
    else {
      digitalWrite(SDOUT,LOW);
      Serial.print(0);
    }
    digitalWrite(SCLK, LOW);
  }
  Serial.println(" This is the DAC value");
  delay(1);
  digitalWrite(CS_DAC1, HIGH);
  delay(1);

 
  //ADC
  // 1. Communication register
  digitalWrite(CS_ADC, LOW);
  digitalWrite(SCLK, HIGH);
  int comm_reg2 = 56;
  for(int i = 0; i < 8; i++) {
    digitalWrite(SCLK,LOW);
    unsigned int mask = 1 << (7 - i);
    if (mask & comm_reg2) {
      digitalWrite(SDOUT,HIGH);
      //Serial.print(1);
    }
    else{
      digitalWrite(SDOUT,LOW);
      //Serial.print(0);
    }
    digitalWrite(SCLK,HIGH);
  }
  digitalWrite(CS_ADC,HIGH);
  digitalWrite(SCLK,HIGH);

  // 3. Data register
  if(digitalRead(DATA_READY) == LOW){
    digitalWrite(CS_ADC,LOW);
    for(int i = 0; i < 16; i++) {
      digitalWrite(SCLK,LOW);
     
     
      if(digitalRead(SDIN) == HIGH){
        Serial.print(1);
      }
      else {
        Serial.print(0);
      }
      digitalWrite(SCLK,HIGH);
     
    }
    //Serial.println(" This is the value that we read with the ADC");
    digitalWrite(CS_ADC, HIGH);
  }
 
 
}

The thing is that I send data to a DAC and then receive it with the ADC and read it from there.
The DAC part works fine, the data is sent perfectly. But the problem arises with the ADC.

My professor told me to first write to the communication register and then to the setup register. This is done only once. After that, in the loop function, everytime I want to read it from the ADC, first I write to the communication register and then read it from the data register. But the DRDY pin is always HIGH. It doesn’t go to low. I’m not sure if I communicate correctly with the ADC.

Thanks

I've deleted your other cross post @syphracos123.

Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.

Repeated cross posting will result in a suspension from the forum.

In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Can you please a hand drawn (at least) picture of the connections you have made between UNO, DAC (what type is it?) and ADC (AD7511).

The ADC (AD7511) is a SPI device; you are trying to read data from it through bit banging. Are you not familiar with SPI Port based Serial Communication?

Hi Pert,

sorry about that. I will take care that this doesn't happens again.

Hi Golam,

I can send you the circuit diagramms that my prof. made. He said that I should do this bit banging because otherwise I would have to change the SPI depending if I use the DAC or the ADC. To be honest, I don't quiet understand this in details how everything is connected and what everything means. In this project I have to write the code only and I try to understand as much of the "connections" as possible.
I saw yesterday that i didn't set the RESET_ADC to high. After I did this, the ADC spits out a value, but only one. I noticed that after the first time the DATA_READY goes from HIGH to low, he stays low. But he should go to HIGH when the "reading with Arduino from ADC" part is done.
So, I'm basically stuck there now.
P.S. the DAC is the AD766