Hi,
I have some problems reading my ADS7828E ADC with the Arduino over I2C
here is the function I wrote to read the ADC
uint16_t readADC(char sensor){
const byte DAT[8] = {0x84,0xE4,0xF4,0xD4,0xA4,0xE4,0xB4,0xF4}; // Just using the first byte for the moment
byte highbyte, lowbyte;
Wire.beginTransmission(ADC7828E_I2C_Adress);
Wire.write(DAT[sensor]);
delay(1);
if (Wire.endTransmission() == 0){
//LOG("ADS7828E recognized");
} else {
ERR("Failed to recognize ADS7828E");
}
delay(1);
uint16_t value;
Wire.requestFrom(ADC7828E_I2C_Adress, 2);
while(Wire.available())
{
highbyte = Wire.read();
lowbyte = Wire.read();
value= ((int)((highbyte<<8) + lowbyte));
}
return(value);
}
I connected the REF Pin to my 5,02V supply (clean 5,02V checked with the oscilloscope).
Im confused because I get two different values, depending on how Im calling the function, does anyone know why?
uint16_t adcvalue =0;
for (int i=0; i<1; i++){
adcvalue +=(readADC(0));
}
Serial.print("single read FOR:");
Serial.println(adcvalue);
Serial.print("single read ADC:");
Serial.println(readADC(0));
which gives me
single read ADC:1283
single read FOR:1250
single read ADC:1283
single read FOR:1244
single read ADC:1285
single read FOR:1255
single read ADC:1289
single read FOR:1254
with oversampling it looks like this
uint16_t adcvalue =0;
for (int i=0; i<10; i++){
adcvalue +=(readADC(0));
}
Serial.print("oversampling read FOR:");
Serial.println(adcvalue/10);
oversampling read FOR:1328
single read ADC:1346
oversampling read FOR:1329
single read ADC:1345
oversampling read FOR:1327
single read ADC:1342
The values are pretty constant, depending on the way the function is called but a direct call vs. a call in the for loop, there is a difference of about 10-13 or single shot more than 30! Why?
Also, the value is off by about 16mV, is this normal?
Thanks!