Hello all,
I'm a newbie and can not handle with this project.
I want to read the result from LTC2440 ADC with connected load cell to it. I found some information but for 7hz output rate which is too slow for me. To get 880Hz output rate the F0 pin of ltc2440 must be grounded and the internal clock is 9Mhz by the datasheet. I read the data from adc but it is not correct. The output data length is 32bit so read 8 bytes, but I am not sure about in which order to place them.
// ARDUINO UNO - LTC2440
// http://cds.linear.com/docs/en/datasheet/2440fd.pdf
// I want to use LTC2440 in internal serial clock, Single cycle operation
// The data is send when CS goes LOW and its lenght is 32bit
// What oscillator to use ??? interal or external ???
// I will try with internal oscillator - F0 grounded?
// when F0 is grounded the internal oscillator is 9Mh = 880Hz output rate
// so will set SCK ( serial clock ) to div16 = 1Mhz
//
//
// http://arduino.cc/en/Reference/SPI
// for UNO - MOSI - SDI PIN11
// MISO - SDO PIN12
// SCK - PIN13
// SS - CS - PIN10
//
#include <SPI.h> // include spi library
byte byte1; // declare 4 bytes because we have to read 32bit data so we have to
byte byte2; // read 4 bytes
byte byte3; //
byte byte4; //
double volts;
byte csPIN = 10; // declare select pin and miso pin
byte misoPIN = 12; //
void setup()
{
Serial.begin(115200); //set serial rate to 115200
pinMode (csPIN, OUTPUT); //declare csPIN as an OUTPUT
digitalWrite( csPIN, HIGH); // set cs pin to high to unsellect the adc - sleep mode
// adc set data when cs goes low
}
void loop()
{
delay(500); //delay for easy monitor the serial printed data
uint32_t startTime = millis(); // declare mins and seconds for time information
long secs;
float mins;
long result = 0;
SPI.begin(); // initialize SPI
SPI.setBitOrder(MSBFIRST); //LTC2440 data is clocked in MSB first
SPI.setDataMode(SPI_MODE0); // is that correct ??? clock polarity 0, clock phase 0
SPI.setClockDivider(SPI_CLOCK_DIV2); // set clock sync to 8MHZ div = 2, because the internal clock of LTC2440 is 9.24MHZ
digitalWrite(csPIN, LOW); // raise the adc
delayMicroseconds(1);
byte1 =0;
byte2 =0;
byte3 =0;
byte4 =0;
byte1 = SPI.transfer(0);
result = byte1;
result = result <<8;
byte2 = SPI.transfer(0);
result |= byte2;
result = result <<8;
byte3 = SPI.transfer(0);
result |= byte3;
result = result <<8;
byte4 = SPI.transfer(0);
result |= byte4;
SPI.end() ;
volts = result*0.1490116119384765625; //my refV = 5V (4.96V), at the bridge output I have 2.48V and the resolution is 2^24 = 16777216
// 2.48 / 2^24 = 0.0000001490116119384765625V = 0.1490116119384765625 for microvolts
digitalWrite(csPIN, HIGH); // set ADC to sleep mode
SPI.end() ;
mins = (float) millis() / 60000; // elapsed time in minutes
Serial.println(mins);
Serial.print("||result");
Serial.print(result, BIN);
Serial.print(byte1, BIN);
Serial.print("||B2=");
Serial.print(byte2, BIN);
Serial.print("||B3=");
Serial.print(byte3, BIN);
Serial.print("||B4=");
Serial.print(byte4, BIN);
Serial.print("microvolts=");
Serial.print(volts);
}