Hello,
I have a question about reading data from mpl3115s2 pressure/altitude sensor. I need to reading data once a minute and I have already chosen the standby mode. I use the following settings:
at start :
set oversampling as 128 in control register 1
set tdfe, drem and pdfe bits in ptDataCfg register
at reading time:
set reference pressure in BAR_IN register
set bit alt in ctrl1 as 1 or 0 depends on altitude or pressure mode
wait 10ms (I don't know if is it necessary)
set ost bit in ctrl1 register
waits for ost bit clearing in loop
waits for ptdr bit in status register
reads 3 bits from pressure out register
converts it into float
I repeat reading operations for pressure and altitude.
Should I chose my approach? I ask because my measurements are usually correct but not always. Sometimes altitude is
65520.000000 or something like this.
Thanks for all answers.
Best regards. Wojciech Jasiewicz.
Hi Wojciech,
Your sequence seems to be correct (I guess 3 bits is just a typo and you mean 3 bytes - registers 0x01 - 0x03).
Do you have such a problem with altitude measurements only or also with pressure? How are you converting the raw values from registers 0x01 - 0x03 to real values in meters? It seems to me like a problem with incorrect conversion/wrong data types.
Best regards,
Tomas
Hi Tomas
Yes, I thought about bytes (register), it was my mistake.
Yes I had problem with pressure (too small, for example 107,555 Pa) and altitude (24410 or 65520 m), but it was for following configuration:
set oversampling as 128 in control register 1
set sysb bit in control register 1
set tdfe, drem and pdfe bits in ptDataCfg register
at reading time:
set reference pressure in BAR_IN register
waits for ptdr bit in status register
reads 3 bits from pressure out register
converts it into float
I thought that status register's reading was sufficient. At current configuration only altitude has bad value.
I use conversions like below:
For pressure:
// raw data from device registers: 2 - LSB, 1 - CSB, 0 - MSB
union32_t integerPart = {.u8 = {rawPressure[2], rawPressure[1], rawPressure[0], 0}};
// converts raw 18-bit integer part to float and adds 2 bits of fractional part, 0x30 - gets 2 bits from LSB byte
return ((float)(integerPart.u32 >> 6)) + ((float)((rawPressure[2] & 0x30) >> 4) * 0.25);
For altitude:
//converts raw: 0 - MSB and 1 - CSB to float form as integer part and adds 4 bits from byte 2 - LSB bytes in float form
return ((float)((int32_t) ((rawAltitude[0] << 8) | rawAltitude[1]))) + ((float)(rawAltitude[2] >> 4) * 0.625);
Best regards. Wojciech Jasiewicz.