Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSB LSB XLSV are not meant to be signed #1

Open
IjonTichyRaumpilot opened this issue Mar 31, 2018 · 1 comment
Open

MSB LSB XLSV are not meant to be signed #1

IjonTichyRaumpilot opened this issue Mar 31, 2018 · 1 comment

Comments

@IjonTichyRaumpilot
Copy link

IjonTichyRaumpilot commented Mar 31, 2018

As I see, you are reading a byte value for MSB, LSB, XLSB to compose the pressure. In Java they are signed. The values are not meant to be signed, so it helps to change the following lines to get it working properly
change line 171-173
int msb = mDevice.readRegByte(BMP180_PRESSURE_DATA);
int lsb = mDevice.readRegByte(BMP180_PRESSURE_DATA + 1);
int xlsb = mDevice.readRegByte(BMP180_PRESSURE_DATA + 2);

to

int msb = ( mDevice.readRegByte(BMP180_PRESSURE_DATA) & 0xff);
int lsb = ( mDevice.readRegByte(BMP180_PRESSURE_DATA + 1) & 0xff);
int xlsb = ( mDevice.readRegByte(BMP180_PRESSURE_DATA + 2) & 0xff);

Similar to the calculation on B4 and B7. As in Java int has 4 bytes that should be big enough to store the unsigned long values in C as in the datasheet (page 15)

line 229-230
long B4 = (AC4 * (X3 + 32768)) >> 15;
long B7 = (UP - B3) * (50000 >> mode);

to
int B4 = (((AC4 * (X3 + 32768)) >> 15)& 0xffffffff);
int B7 = ((UP - B3) * (50000 >> mode)& 0xffffffff);

See
https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMP180-DS000-12.pdf
https://stackoverflow.com/questions/4266756/can-we-make-unsigned-byte-in-java

Similar problems may occur with AC4, AC5, AC6 as they are unsigned short and read as byte (signed in JAVA)

@Chris1234567899
Copy link

@IjonTichyRaumpilot is right I think. After implementing his suggestions I get fairly correct values. Before that is was way off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants