aledio:
I have changed the data type definition.
Now, I read on the channel AIN6-AIN6 the value ABB0D5 but on the others channels 0.
I don't understand if the problem is the SPI configuration or the communication protocol.
I have observed that my program does not read correctly register values. I try to write this code:
void setup() {
// configure AD7714
writeRegister(0x20 | channel); /* set the channel AIN6/AIN6 and set the next operation as write to the filter high
register /
writeRegister(0x4f); / set Bipolar mode, 24 bits, boost off, all 4 MSBs of filterword to 1 /
writeRegister(0x28 | channel);
digitalWrite(chipSelect, LOW);
conf = SPI.transfer(0);
digitalWrite(chipSelect, HIGH);
Serial.println(conf, HEX);
writeRegister(0x30 | channel); / set the next operation as a write to the filter low register /
writeRegister(0xA0); / max filter word allowed for low part of the filterword /
writeRegister(0x38 | channel);
digitalWrite(chipSelect, LOW);
conf = SPI.transfer(0);
digitalWrite(chipSelect, HIGH);
Serial.println(conf, HEX);
writeRegister(0x10 | channel); / set the operation as a write to the mode register /
writeRegister(0x20); / set gain to 1, burnout current off, no filter sync, and do a self calibration */
writeRegister(0x18 | channel);
digitalWrite(chipSelect, LOW);
conf = SPI.transfer(0);
digitalWrite(chipSelect, HIGH);
Serial.println(conf, HEX);
// give the sensor time to set up:
delay(100);
}
The value of "conf" variable should be equal to the written value, but it is not so.
What is the code for writeRegister()?
Everytime the chipSelect is driven Low, it starts a NEW transaction, the ADC expects the COMM register read/write mode plus any other register.
your code:
writeRegister(0x30 | channel); /* set the next operation as a write to the filter low register */
writeRegister(0xA0); /* max filter word allowed for low part of the filterword */
writeRegister(0x38 | channel);
digitalWrite(chipSelect, LOW); // ***** this starts a NEW transaction
conf = SPI.transfer(0); // ***** writes 0 to the COMM register, Selects Ain1,Ain6
digitalWrite(chipSelect, HIGH); // ***** ends transaction
Serial.println(conf, HEX);
I assume that each writeRegister()
- takes CS low
- creates a COMM value
- SPI.transfer(); the COMM value
- SPI.transfer(); any other register value, 8bit or 16bit or 24bit (multiple calls)
- takes CS HIGH
So, in this code snippet the:
digitalWrite(chipSelect, LOW);
conf = SPI.transfer(0);
digitalWrite(chipSelect, HIGH);
sends 0 as the current COMM value, (register 0 write, Ain1,Ain6). I don't think that was what you wanted.
Have you tried the code I wrote?
Also, do you have a pullup on the Data_ready Line?
Chuck.