STMicroelectronics / STMems_Standard_C_drivers

Platform-independent drivers for STMicroelectronics MEMS motion and environmental sensors, based on standard C programming language.
BSD 3-Clause "New" or "Revised" License
732 stars 519 forks source link

lps2x series sensors lps2xx_pressure_raw_get() API return wrong raw pressure data #170

Open zackermei opened 3 weeks ago

zackermei commented 3 weeks ago

According to lps22hb datasheet, the pressure data are stored in 3 registers, so the last line *buff *= 256; of below API should be removed. I had confirmed this issue in lps22hb, and checked other lps2x series sensors, looks like they had the same issue.

int32_t lps22hb_pressure_raw_get(const stmdev_ctx_t *ctx, uint32_t *buff)
{
  uint8_t reg[3];
  int32_t ret;

  ret =  lps22hb_read_reg(ctx, LPS22HB_PRESS_OUT_XL, reg, 3);
  *buff = reg[2];
  *buff = (*buff * 256) + reg[1];
  *buff = (*buff * 256) + reg[0];
  *buff *= 256; /* this line should be removed */

  return ret;
}
zackermei commented 3 weeks ago

this issue had been mention by others as well. https://github.com/STMicroelectronics/lps22hb-pid/issues/1