Parallax MS5607 Altimeter module incorrect altitude & calibration question

Hi all-
I am trying to get the altitude out of the MS5607 altimeter module by Parallax:
http://learn.parallax.com/KickStart/29124

Using the code and libraries provided, my results are negative and the altitude results increase as I go down in height and decreases as I go up. I have also tried these in the Arduino Forums to no avail:
http://forum.arduino.cc/index.php?topic=104247.0
http://forum.dev.arduino.cc/index.php?topic=156339.0
Any ideas what the issue is? My setup is an Arduino Uno Rev. 3/Arduino Micro (assuming the SCL and SDA ports work the same) and the altimeter module (wired the same manner as in the Parallax link above) along with Arduino Version 1.0.5. Also, how do I calibrate it? Could I get some assistance in this? Any help would be appreciated!

Post your code and some sample output.

Here's what I'm using:

#include <Wire.h>
#include "IntersemaBaro.h"

Intersema::BaroPressure_MS5607B baro(true);

void setup() { 
    Serial.begin(9600);
    baro.init();
}

void loop() {
  int alt = baro.getHeightCentiMeters();
  Serial.print("Centimeters: ");
  Serial.print((float)(alt));
  Serial.print(", Feet: ");
  Serial.println((float)(alt) / 30.48);
   
  int temp = baro.getTemperature(); 
  Serial.print("Temperature: "); 
  Serial.println(temp);
  delay(1000); 
}

The library can be downloaded from the Parallax link I posted previously.
I just realized-the sensor works well w/ this bit of code works IF the sensor is hooked up to the 3.3V port.

entimeters: 2655.00, Feet: 87.11
Temperature: 69
Centimeters: 2680.00, Feet: 87.93
Temperature: 69
Centimeters: 2689.00, Feet: 88.22
Temperature: 69
Centimeters: 2714.00, Feet: 89.04
Temperature: 69
Centimeters: 2730.00, Feet: 89.57
Temperature: 69
Centimeters: 2730.00, Feet: 89.57
Temperature: 69
Centimeters: 2755.00, Feet: 90.39
Temperature: 69
Centimeters: 2747.00, Feet: 90.12
Temperature: 69
Centimeters: 2772.00, Feet: 90.94
Temperature: 69
Centimeters: 2705.00, Feet: 88.75
Temperature: 69
Centimeters: 2705.00, Feet: 88.75
Temperature: 69
Centimeters: 2722.00, Feet: 89.30
Temperature: 69

This is the typical results (going up). The temperature is off-the temp in my apartment is 76F. Any ideas how to fix that? Also how do I calibrate the AGL pressure? And how do I get the raw pressure in Pascals?

You may have to modify the library code to get the raw pressure readings. I didn't look at it very carefully, but here is where the altitude is calculated from the averaged pressure readings:

  virtual int32_t AcquireAveragedSampleCm(const uint8_t nSamples)
    {
        int64_t pressAccum = 0;

        for(size_t n = nSamples; n; n--) 
        {
            const uint32_t temperature = ReadAdc(cmdAdcD2_ | cmdAdc4096_); // digital temperature value : typical 8077636  
            const uint32_t pressure    = ReadAdc(cmdAdcD1_ | cmdAdc4096_); // digital pressure value : typical 6465444        
            const uint32_t pressConv   = ConvertPressureTemperature(pressure, temperature);                 
            pressAccum += pressConv;
/*
(commented out code)
*/
        }

        const int32_t pressAvg = pressAccum / nSamples;        
        const int32_t AltCm = PascalToCentimeter(pressAvg);
	
        return AltCm;

Hi,
I'm running the MS5607 using the SPI.h library on a OSEPP Mega 2560 R3 Plus - Arduino 1.0.4.

Using that sensor is a little deeper than a short post, but here are the results with both a 2-Byte and 3-Byte read using SPI.transfer():

Reset

Read Prom Command: 162
MSB: 180
LSB: 180
PROM Read Value: 46260

Read Prom Command: 164
MSB: 158
LSB: 80
PROM Read Value: 40528

Read Prom Command: 166
MSB: 114
LSB: 122
PROM Read Value: 29306

Read Prom Command: 168
MSB: 105
LSB: 183
PROM Read Value: 27063

Read Prom Command: 170
MSB: 127
LSB: 181
PROM Read Value: 32693

Read Prom Command: 172
MSB: 110
LSB: 50
PROM Read Value: 28210

ADC Conversion Command: 88
ADC Read Command: 0
Most Significant Bits: 130
Middle Significant Bits: 59
Least Significant Bits: 174
ADC Read Value: 8534958

ADC Conversion Command: 72
ADC Read Command: 0
Most Significant Bits: 90
Middle Significant Bits: 68
Least Significant Bits: 198
ADC Read Value: 5915846

Raw Temperature: 8534958

C[5] = 32693
C[6] = 28210

dT: 165550
Temperature: 2556

Raw Pressure: 5915846

C[1] = 46260
C[3] = 29306
C[2] = 40528
C[4] = 27063

OFFSET: 5382090385
Sensitivity: 3069598549
Pressure: 100003
Temperature: 25.56, Pressure: 1000.03
Centimeters: 11069.00, Feet: 363.16

Time = 00:42:44, Date (D/M/Y) = 15/11/2013

When I figure out the Creative Commons, I'll attach the modified IntersemaBaro.h.

If you continue to read the SPI without sending a MS5607 command, the entire register can be read.

But based on experience I can't recommend using the SPI interface for this sensor at 5V logic. Even some I2C devices cause I2C communication failures with this sensor, too.

Anyone ever check IntersemaBaro.h for data-type-conversion errors in the calculations? I recall having to change type declaration ordering to have the math match.

Also a bit curious what launch stress will do on circuit performance, especially the effect on this grade of crystal oscillators.

    case 2: // SPI
     {
        digitalWrite(baro_ss, LOW);
        SPI.setBitOrder(MSBFIRST);
        SPI.setClockDivider(SPI_CLOCK_DIV8);
        SPI.begin();
        SPI.transfer(cmdPromRd_ + coefNum * 2);
        {
            byte ret1 = SPI.transfer(0xff);   // read MSB
            byte ret2 = SPI.transfer(0xff);   // read LSB

            uint16_t rC  = ret1 * 256;
            rC  = rC + ret2;
            SPI.end();
            digitalWrite(baro_ss, HIGH);
            
#ifdef DEBUG
            Serial.println();
    	    Serial.print("Read Prom Command: ");
            Serial.println(cmdPromRd_ + coefNum * 2);
            Serial.print("MSB: ");
            Serial.println(ret1);
            Serial.print("LSB: ");
            Serial.println(ret2);
            Serial.print("PROM Read Value: ");
            Serial.println(rC);
#endif
            return rC;
            
        break;
       }
	   
/////////////	   
	   
     case 2: // SPI
      {
        digitalWrite(baro_ss, LOW);
        SPI.setBitOrder(MSBFIRST);
        SPI.setClockDivider(SPI_CLOCK_DIV8);
        SPI.begin();
        SPI.transfer(cmdAdcConv_ | cmd);
        digitalWrite(baro_ss, HIGH);
        SPI.end();
        
#ifdef DEBUG
        Serial.println();
        Serial.print("ADC Conversion Command: ");
        Serial.println(cmdAdcConv_ | cmd);
#endif 

        break;
       }
	   
///////////	   
	   
     case 2: // SPI
      {
        digitalWrite(baro_ss, LOW);
        SPI.setBitOrder(MSBFIRST);
        SPI.setClockDivider(SPI_CLOCK_DIV8);
        SPI.begin();
        SPI.transfer(cmdAdcRead_);
        {
            byte ret1 = SPI.transfer(0xff);   // read MostSB
            byte ret2 = SPI.transfer(0xff);   // read MiddleB
            byte ret3 = SPI.transfer(0xff);   // read LeastSB
            
            uint32_t temp  = 65536 * ret1;
            temp = temp + 256 * ret2;
            temp = temp + ret3;
            
            SPI.end();
            digitalWrite(baro_ss, HIGH);

#ifdef DEBUG            
	    Serial.print("ADC Read Command: ");
        Serial.println(cmdAdcRead_);
	    Serial.print("Most Significant Bits: ");
        Serial.println(ret1);
	    Serial.print("Middle Bits: ");
        Serial.println(ret2);
	    Serial.print("Least Significant Bits: ");
        Serial.println(ret3);
	    Serial.print("ADC Read Value: ");
        Serial.println(temp);
#endif 
            return temp;
        }  
        break;
      }