Hi,
I have been asked to look at a mates arduino project, he needs to read data from 2 load sensors and then pass that data back into another application to record strain over time.
We have selected the AD7730 as our ADC.
There will only be one SPI device connected to this project, so no need for cs pin to go high.
I have managed to get it calibrating (i think) and outputting data, however i can not seem to get the ready pin to go low after calibration.
It needs to read a min/max -15mV to +15mV , hence i have set it up in unipolar and 20mV scale.
Code attached, constructive criticism please ![]()
really want to know if it has calibrated, and if the data i am receiving is good.
Thanks,
Tim
aka
Kremit
/*
Circuit:
DRDY: pin 9
CSB: pin 10
MOSI: pin 11
MISO: pin 12
SCK: pin 13
Reset pin: 8
*/
// the sensor communicates using SPI, so include the library:
#include <SPI.h>
// pins used for the connection with the sensor
// the other you need are controlled by the SPI library):
const int RDY = 9;
const int chipSelectPin = 10;
const int resetpin= 8;
byte byte1;
byte byte2;
byte byte3;
byte byte_total;
void setup() {
Serial.begin(9600);
// start the SPI library:
Serial.println("Setting up SPI ...");
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV16);
Serial.println("Reset ADC ...");
digitalWrite(resetpin,HIGH);
delay(1000);
digitalWrite(resetpin,LOW);
delay(1000);
digitalWrite(resetpin,HIGH);
delay(1000);
Serial.println("Set Filter register settings");
SPI.transfer(0x03);//Write 03 Hex to Serial Port1 /* Writes to Communications Register Setting Next Operation as Write to Filter Register*/
SPI.transfer(0x200010);//Write 200010 Hex to Serial Port1 /* Writes to Filter Register Setting a 200 Hz Output Rate in CHOP Mode*/
Serial.println("Set DAC register settings");
SPI.transfer(0x04);//Write 04 Hex to Serial Port1 /* Writes to Communications Register Setting Next Operation as Write to DAC Register*/
SPI.transfer(0x23);//Write 23 Hex to Serial Port1 /* Writes to DAC Register Setting a Subtraction Value of 7.5 mV (5 V Reference) on the TARE DAC*/
Serial.println("Channel 1 Internal full scale calibration");
SPI.transfer(0x02);//Write 02 Hex to Serial Port /* Writes to Communications Register Setting Next Operation as Write to Mode Register*/
SPI.transfer(0xA190);//Write A190 Hex to Serial Port /* Writes to Mode Register Initiating Internal Full-Scale Calibration for -20 mV to +20 mV Input Range chan 1*
//while(digitalRead(RDY) != LOW) {Serial.print(".");delay(1000);} // wait for RDY signal from AD7730
delay(1000);
Serial.println("Channel 2 Internal full scale calibration");
SPI.transfer(0x02);//Write 02 Hex to Serial Port /* Writes to Communications Register Setting Next Operation as Write to Mode Register*/
SPI.transfer(0xA191);//Write A191 Hex to Serial Port /* Writes to Mode Register Initiating Internal Full-Scale Calibration for -20 mV to +20 mV Input Range chan 2*
delay(1000);
Serial.println("Calibration done");
Serial.println("Commence data aquisition..");
Serial.println("Data as channel no: byte 1, byte 2, byte 3, decimal value");
delay(1000);
}
void loop() {
SPI.transfer(0x02);
SPI.transfer(0x2190); //continuous read from channel 1
readandprint(1);
SPI.transfer(0x30); //end continous mode
delay(1000);
SPI.transfer(0x02);
SPI.transfer(0x2191); //continous read from channel 2
readandprint(2);
SPI.transfer(0x30); //end continous mode
delay(1000);
}
void readandprint(int chan)
{
byte1 = SPI.transfer(0x00);
byte2 = SPI.transfer(0x00);
byte3 = SPI.transfer(0x00);
byte_total=byte1<<16;
byte2=byte2<<8;
byte_total= byte_total|byte2|byte3;
byte_total=(byte_total*2)+byte_total;
Serial.print(chan);
Serial.print(": ");
Serial.print(byte1,BIN);
Serial.print(" ");
Serial.print(byte2,BIN);
Serial.print(" ");
Serial.print(byte3,BIN);
Serial.print(" ");
Serial.print(byte_total, DEC);
Serial.print("\n");
delay(1000);
}