Skip to content

Commit

Permalink
Fix of LPS25H temperature reading when moving avg filter is activated.
Browse files Browse the repository at this point in the history
Reading of LPS25H temp register must be done in separate read as the
register auto increment pointer wraps around in the pressure registers
when FIFO mode is enabled. As described in AN4450 5.1 from ST. Closes
#149
  • Loading branch information
tobbeanton committed Sep 20, 2016
1 parent 0e842f2 commit 3ca3d35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/drivers/src/lps25h.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ bool lps25hSetEnabled(bool enable)
status = i2cdevWrite(I2Cx, devAddr, LPS25H_CTRL_REG1, 1, &enable_mask);
enable_mask = 0b00001111; // AVG-P 512, AVG-T 64
status = i2cdevWrite(I2Cx, devAddr, LPS25H_RES_CONF, 1, &enable_mask);
// FIFO averaging
// FIFO averaging. This requres temp reg to be read in different read as reg auto inc
// wraps back to LPS25H_PRESS_OUT_L after LPS25H_PRESS_OUT_H is read.
enable_mask = 0b11000011; // FIFO Mean mode, 4 moving average
status = i2cdevWrite(I2Cx, devAddr, LPS25H_FIFO_CTRL, 1, &enable_mask);
enable_mask = 0b01000000; // FIFO Enable
Expand Down
14 changes: 12 additions & 2 deletions src/hal/src/sensors_cf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
// Buffer length for MPU9250 slave reads
#define SENSORS_MPU6500_BUFF_LEN 14
#define SENSORS_MAG_BUFF_LEN 8
#define SENSORS_BARO_BUFF_LEN 6
#define SENSORS_BARO_BUFF_S_P_LEN 4
#define SENSORS_BARO_BUFF_T_LEN 2
#define SENSORS_BARO_BUFF_LEN (SENSORS_BARO_BUFF_S_P_LEN + SENSORS_BARO_BUFF_T_LEN)

#define GYRO_NBR_OF_AXES 3
#define GYRO_MIN_BIAS_TIMEOUT_MS M2T(1*1000)
Expand Down Expand Up @@ -424,11 +426,19 @@ static void sensorsSetupSlaveRead(void)
if (isBarometerPresent)
{
// Configure the LPS25H as a slave and enable read
// Setting up two reads works for LPS25H fifo avg filter as well as the
// auto inc wraps back to LPS25H_PRESS_OUT_L after LPS25H_PRESS_OUT_H is read.
mpu6500SetSlaveAddress(1, 0x80 | LPS25H_I2C_ADDR);
mpu6500SetSlaveRegister(1, LPS25H_STATUS_REG | LPS25H_ADDR_AUTO_INC);
mpu6500SetSlaveDataLength(1, SENSORS_BARO_BUFF_LEN);
mpu6500SetSlaveDataLength(1, SENSORS_BARO_BUFF_S_P_LEN);
mpu6500SetSlaveDelayEnabled(1, true);
mpu6500SetSlaveEnabled(1, true);

mpu6500SetSlaveAddress(2, 0x80 | LPS25H_I2C_ADDR);
mpu6500SetSlaveRegister(2, LPS25H_TEMP_OUT_L | LPS25H_ADDR_AUTO_INC);
mpu6500SetSlaveDataLength(2, SENSORS_BARO_BUFF_T_LEN);
mpu6500SetSlaveDelayEnabled(2, true);
mpu6500SetSlaveEnabled(2, true);
}
#endif

Expand Down

0 comments on commit 3ca3d35

Please sign in to comment.