Go Down

Topic: Problem with Interfacing AD7730 (Read 106 times) previous topic - next topic

harikeshpatil


Hello..

I am facing problem with Interfacing AD7730 with Arduino- ATMEGA328P-AU. The Circuit Diagram, Codes and Serial Output are attached.
I am getting output 0 and Ready Pin goes to High after 1st scan in loop. I have cheeked Ready Pulses on LED attached to this Pin. The Codes are as per the Data Sheet- Page No 37.

Filter- 50Hz
Tare- 7.5 mV
Full Scale Range- 0-10mV

I think, the problem with the Calibration, please help me. Anybody have working code for the same.

Regards,
Harikesh

pylon

This line does not send 3 bytes to the chip but only one:

Code: [Select]
  SPI.transfer(0x800010);


You have to issued three consecutive calls to SPI.transfer() to send a 24bit value.

In my opinion the datasheet is not very clear about how to use the CS line to distinguish different write acesses. I would try the same as you do but if that does not work, don't pull CS HIGH between the write to the communication register and the data that is to be written to the addressed register.


harikeshpatil

Hello Pylon,
Thanks for the reply.
I have tried but, Ready is not going low.
Below are the codes.
Harikesh

Code: [Select]
#include <SPI.h>
#define RESET 8 //
#define RDY 9

byte byte1;
byte byte2;
byte byte3;
long byte_total;
long time;

void setup()
{
  pinMode(RDY, INPUT);
  pinMode(RESET, OUTPUT);
  pinMode(SCK,OUTPUT);
  digitalWrite(SS, HIGH);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE3);
  SPI.setClockDivider(SPI_CLOCK_DIV16);
  Serial.begin(9600);
 
  Serial.println("Reset ADC ...");
  digitalWrite(RESET,HIGH);
  delay(500);
  digitalWrite(RESET,LOW);
  delay(500);
  digitalWrite(RESET,HIGH);
  delay(500);
  Serial.println("Set up AD7730");
  digitalWrite(SS,LOW);
  SPI.transfer(0x03);
  digitalWrite(SS,HIGH);
  //delay(100);
  digitalWrite(SS,LOW);
  //SPI.transfer(0x800010);
  SPI.transfer(0x10);
  SPI.transfer(0x00);
  SPI.transfer(0x80);
  digitalWrite(SS,HIGH);
  //delay(100);
  Serial.println("Set DAC register settings");
  digitalWrite(SS,LOW);
  SPI.transfer(0x04);
  digitalWrite(SS,HIGH);
  //delay(100);
  digitalWrite(SS,LOW);
  SPI.transfer(0x23);
  digitalWrite(SS,HIGH);
  //delay(100);
  Serial.println("Channel 1 Internal full scale calibration");
  digitalWrite(SS,LOW);
  SPI.transfer(0x02);
  digitalWrite(SS,HIGH);
  //delay(100);
  digitalWrite(SS,LOW);
  SPI.transfer(0xB180);// Initiating Internal Full Scale 0 to +10mv
  digitalWrite(SS,HIGH);
  digitalWrite(SS,LOW);
  SPI.transfer(0x02);
  digitalWrite(SS,HIGH);
  while(digitalRead(RDY) !=LOW) { Serial.println("calibration wait RDY"); delay(500); }
  Serial.println("calibration done");
  digitalWrite(SS,LOW);
  SPI.transfer(0x02);
  digitalWrite(SS,HIGH);
  //delay(100);
  digitalWrite(SS,LOW);
  //SPI.transfer(0x9180);
  SPI.transfer(0x80);
  SPI.transfer(0x91);
  SPI.transfer(0x00);
  digitalWrite(SS,HIGH);
  digitalWrite(SS,LOW);
  SPI.transfer(0x02);
  digitalWrite(SS,HIGH);
  delay(100);
  while(digitalRead(RDY) !=LOW) { Serial.println("wait for RDY signal to goes LOW IN VOID SETUP2"); delay(500); }
}
   
void loop() {
  digitalWrite(SS,LOW);
  SPI.transfer(0x02);
  digitalWrite(SS,HIGH);
  //delay(100);
  digitalWrite(SS,LOW);
  //SPI.transfer(0x2180); //continuous read from channel 1
  SPI.transfer(0x80);
  SPI.transfer(0x21);
  SPI.transfer(0x00);
  digitalWrite(SS,HIGH);
  //delay(100);
  digitalWrite(SS,LOW);
  SPI.transfer(0x21);
  digitalWrite(SS,HIGH);
  //delay(100);
  while(digitalRead(RDY) !=LOW){
    Serial.println("NOT RDY IN VOID LOOP");
    delay (1000);
  }
 
  delay(100);
  digitalWrite(SS,LOW);
  byte1 = SPI.transfer(0xff);
  byte2 = SPI.transfer(0xff);
  byte3 = SPI.transfer(0xff);
  digitalWrite(SS,HIGH);
  byte_total = (long)byte1 << 16;
  byte_total += (long)byte2 << 8;
  byte_total += (long)byte3;

  SPI.transfer(0x30); //end continous mode
 
  Serial.print(byte1,BIN); Serial.print(" ");
  Serial.print(byte2,BIN); Serial.print(" ");
  Serial.print(byte3,BIN); Serial.print(" ");
  Serial.print(byte_total); Serial.print("\n");
  //delay(1000);
}

pylon

You have to change every location in the code where you tried to send more than one byte:

Code: [Select]
  SPI.transfer(0xB180);// Initiating Internal Full Scale 0 to +10mv

harikeshpatil

It's not working..

Serial Port Message: wait for RDY signal to goes LOW IN VOID SETUP2

Pl help out

pylon

Code: [Select]
  //SPI.transfer(0x800010);
  SPI.transfer(0x10);
  SPI.transfer(0x00);
  SPI.transfer(0x80);


SPI is set to MSBFIRST mode, why do you think that the least significant byte has to be transfered first?

Go Up