I am a little confused about the data types of uncompensated pressure and temperature. In the code sparkfun code, the data types are unsigned while at datasheet(page 13), those are long, which I suppose to be 2s' complement.
For other registers, such as AC1, AC2...., I used 2s' complement and got the values right. I see the same comment for these registers at sourceforge by using 2s’ complement
For uncompensated pressure, I am unable to make it right with signed while able to make it right with unsigned. For temperature, i am still using signed type now and doesn't produce any issue.
Would like to hear your input.
Tell us more about what is or isn't right.
It looks like the Sparkfun code is consistent with the sample code on page 13 of the datasheet. AC1-3 are signed and 4-6 are unsigned.
The only thing that comes to mind is the data from the sensor is short and the Sparkfun / Arduino code is integer. I don't remember all the rules (I'm a hardware guy) but if the value isn't passed correctly from short to integer you could end up with only the least significant byte copied into the integer variable. The top bit isn't set and it becomes a larger positive number instead of the correct negative number.
I see the sparkfun code is consistent with datasheet for AC1-6, but inconsistent for UP and UT. UP and UT in the datasheet are signed while in the code, they are unsigned.
The datasheet specifies UP to be long, but when it is actually used, the datasheet has this: [quote]B7 = ((unsigned long)UP - B3) * (50000 >> oss)
This casts UP as an unsigned long. UP is constructed from only three bytes so there's no chance of a problem - it'll be positive no matter what. Therefore it doesn't matter if UP is originally declared as long and then cast as (unsigned long) or whether it is just declared to be (unsigned long).
FYI: Message #3 is from me. The forum software performed a major screwup with my account while I was posting that message and now I can't even edit it to correct the formatting errors.