Hi,
I have been trying to get realistic results from 2 pressure sensors, the MS5611 and the MS5803. I have had no problem with the Bosch BMP085 which works fine.
(http://www.meas-spec.com/downloads/ms5611-01ba01.pdf
http://www.meas-spec.com/downloads/MS5803-01BA.pdf)
I have tried two breakout boards for the 5611 and 1 for the 5803.
I am getting incorrect results on all 3 boards so I must be doing something fundamentally wrong.
I am using them both in I2C mode.
The pressure and temperature calculations are the same for both boards but the second order corrections differ and have not been used.
The results I get are:
Actual TEMP= 1908 (=19.08C) Actual PRESSURE= 6
RAW Temp D2= 8004242 RAW Pressure D1= 8028974
dT= 7955602
C0/1= 53520
C1/2= 53270
C2/3= 34137
C3/4= 31191
C4/5= 31166
C5/6= 29055
C6/7= 64770
C7/8= 8826
The temperature does not change when I touch the board unlike the Bosch which is very responsive. So perhaps this says what I am doing wrong.
In the temperature calculation I get a value of 7955602 for dT when the example / typical value should be 2366. So as dT=D2-C5*2^8 the error must lie in either D2 or C5. For both sensors the example value for D2 is 8569150 / 8387300 respectively. I obtain 7955602 here for the 5611 so the error is either in C5 or D2. D2 is measured at 8004242 and C4 is 31191 which when multiplied by 256 gives 7984896 and a difference 19346 still far from the typical value of 2366 but far from 7955602 from the serial.print D2 which I get.
Given that I cannot have 3 faulty sensors unless I over cooked them I am lost, please help.
#include <Wire.h>
#define ADDRESS 0x77 //0x76
uint32_t D1 = 0;
uint32_t D2 = 0;
int32_t dT = 0;
int32_t TEMP = 0;
int64_t OFF = 0;
int64_t SENS = 0;
int32_t P = 0;
uint16_t C[7];
void setup() {
// Disable internal pullups, 10Kohms are on the breakout
PORTC |= (1 << 4);
PORTC |= (1 << 5);
Wire.begin();
Serial.begin(9600); //9600 changed 'cos of timing?
delay(100);
initial(ADDRESS);
}
void loop()
{
D1 = getVal(ADDRESS, 0x48); // Pressure raw
D2 = getVal(ADDRESS, 0x58);// Temperature raw
dT = D2 - (C[4]*256);
TEMP = 2000 + ((dT * C[5])/8388608);
OFF = ((C[1])<<16) + ((C[3] * dT) >> 7);
SENS = ((C[0])<<15) + ((C[2] * dT) >> 8);
P = ((D1 * SENS/2097152 - OFF)/32768)/100;
Serial.print(" Actual TEMP= ");
Serial.print(TEMP);
Serial.print(" Actual PRESSURE= ");
Serial.print(P);
Serial.println();
Serial.print(" RAW Temp D2= ");
Serial.print(D2);
Serial.print(" RAW Pressure D1= ");
Serial.println(D1);
Serial.println();
Serial.print(" dT= ");
Serial.println(dT);
Serial.println();
Serial.print(" C0/1= ");
Serial.println(C[0]);
Serial.print(" C1/2= ");
Serial.println(C[1]);
Serial.print(" C2/3= ");
Serial.println(C[2]);
Serial.print(" C3/4= ");
Serial.println(C[3]);
Serial.print(" C4/5= ");
Serial.println(C[4]);
Serial.print(" C5/6= ");
Serial.println(C[5]);
Serial.print(" C6/7= ");
Serial.println(C[6]);
Serial.print(" C7/8= ");
Serial.println(C[7]);
Serial.println();
delay(1000
);
}
long getVal(int address, byte code)
{
unsigned long ret = 0;
Wire.beginTransmission(address);
Wire.write(code);
Wire.endTransmission();
delay(10);
// start read sequence
Wire.beginTransmission(address);
Wire.write((byte) 0x00);
Wire.endTransmission();
Wire.beginTransmission(address);
Wire.requestFrom(address, (int)3);
if(Wire.available()) {
// ret = ((uint32_t)Wire.read() << 16) | ((uint32_t)Wire.read() << 8) | Wire.read();
ret = Wire.read() * 65536 + Wire.read() * 256 + Wire.read();
}
else {
ret = -1;
}
Wire.endTransmission();
return ret;
}
void initial(uint8_t address)
{
Serial.println();
Serial.println("PROM COEFFICIENTS ivan");
Wire.beginTransmission(address);
Wire.write(0x1E); // reset
Wire.endTransmission();
delay(10);
for (int i=0; i<7 ; i++) {
Wire.beginTransmission(address);
Wire.write(0xA2 + (i * 2));
Wire.endTransmission();
Wire.beginTransmission(address);
Wire.requestFrom(address, (uint8_t) 6);
delay(1);
if(Wire.available()) {
C[i] = Wire.read() *256 + Wire.read();
}
else {
Serial.println("Error reading PROM 1"); // error reading the PROM or communicating with the device
}
Serial.println(C[i]);
}
Serial.println();
}