Hallo,
I'm trying to read altitude data from MPL3115A2 but I'm stuck into a strange error.
I'm able to read and write values on registers trough I2C interface indeed I can read correctly the ID value (0xC4) and I'm also able to write and read back values from any other registers (test made on CTRL_REG1, PT_DATA_CFG).
I'm following the Quick Setup procedure in MPL3115A2 datasheet (pag 10, polling mode) I collected the values from:
OUT_P_MSB,
OUT_P_CSB,
OUT_P_LSB,
OUT_T_MSB,
OUT_T_LSB
The OUT_T_xx values seems correct since they can be converted to a float value around 24 degrees (that's a reasonable temperature value in the test environment).
The problem arise with OUT_P_xxx values . OUT_P_MSB is always set to 0xFF value ... I've not investigated yet trough oscilloscope but it seems like the IC it's
not correctly replying to the read request (but just for the first byte value since CSB and LSB values are not fixed but variates around a steady value).
Typical values collected from T registers are: 0x18A0
Typical values collected from P registers are: 0xFFC5C0
Best Regards,
Michele Santucci
Solved! Go to Solution.
Hi Michele,
What you are reading is correct. If you convert 0xFFC5C0 to a signed fractional 20-bit value in meters, you will get about -58.25 meters.
As you can see in my example project, you should use something like this:
Altitude = (float) ((short) ((OUT_P_MSB_REG << 8) | OUT_P_CSB_REG )) + (float) (OUT_P_LSB_REG >> 4) * 0.0625;
For information on how the MPL3115A2 internally calculates altitude, please look at the AN4528 or this article. As you can notice, the calculated altitude is negative if the measured pressure is higher than 1013.26 hPa, which is the default pressure reference at sea level stored in the BAR_IN_MSB (0x14) and BAR_IN_LSB (0x15) registers.
To adjust the most precise altitude, I recommend the following:
1. If you know your current position and the altitude using some external calibration point in meters, then adjust the OFF_H register (0x2D) to account for the discrepancy.
2. If you would like to adjust to weather changes, the BAR_IN_MSB and BAR_IN_LSB registers allow you to modify the default pressure value (1013.26 hPa) that internally is used in the equation that converts pressure in Pascals to meters for altitude, as mentioned above. So if there is a very stormy day and your local weather/airport gives the pressure normalized for sea level, this value should go into these registers. This should bring the height closer and additional will require the OFF_H adjustment.
I hope it helps.
Regards,
Tomas
PS: If my answer helps to solve your question, please mark it as "Correct" or “Helpful”. Thank you.
Hi Michele,
What you are reading is correct. If you convert 0xFFC5C0 to a signed fractional 20-bit value in meters, you will get about -58.25 meters.
As you can see in my example project, you should use something like this:
Altitude = (float) ((short) ((OUT_P_MSB_REG << 8) | OUT_P_CSB_REG )) + (float) (OUT_P_LSB_REG >> 4) * 0.0625;
For information on how the MPL3115A2 internally calculates altitude, please look at the AN4528 or this article. As you can notice, the calculated altitude is negative if the measured pressure is higher than 1013.26 hPa, which is the default pressure reference at sea level stored in the BAR_IN_MSB (0x14) and BAR_IN_LSB (0x15) registers.
To adjust the most precise altitude, I recommend the following:
1. If you know your current position and the altitude using some external calibration point in meters, then adjust the OFF_H register (0x2D) to account for the discrepancy.
2. If you would like to adjust to weather changes, the BAR_IN_MSB and BAR_IN_LSB registers allow you to modify the default pressure value (1013.26 hPa) that internally is used in the equation that converts pressure in Pascals to meters for altitude, as mentioned above. So if there is a very stormy day and your local weather/airport gives the pressure normalized for sea level, this value should go into these registers. This should bring the height closer and additional will require the OFF_H adjustment.
I hope it helps.
Regards,
Tomas
PS: If my answer helps to solve your question, please mark it as "Correct" or “Helpful”. Thank you.
Hallo Tomas,
thanks for the reply. It looks like it's working . I'have some doubt about reading results after the BAR_IN offset registration.