From 2b8e65374e1ebfb2317e0c6eb7b16355d03e4f72 Mon Sep 17 00:00:00 2001 From: mikeller Date: Tue, 23 Feb 2021 01:38:10 +1300 Subject: [PATCH] Fixed initialisation of DPS310 when used over I2C. --- src/main/drivers/barometer/barometer_dps310.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/drivers/barometer/barometer_dps310.c b/src/main/drivers/barometer/barometer_dps310.c index f614a15003..400ded43c6 100644 --- a/src/main/drivers/barometer/barometer_dps310.c +++ b/src/main/drivers/barometer/barometer_dps310.c @@ -165,8 +165,16 @@ static bool deviceConfigure(busDevice_t * busDev) // 1. Read the pressure calibration coefficients (c00, c10, c20, c30, c01, c11, and c21) from the Calibration Coefficient register. // Note: The coefficients read from the coefficient register are 2's complement numbers. - uint8_t coef[18]; - if (!busReadBuf(busDev, DPS310_REG_COEF, coef, sizeof(coef))) { + + // Do the read of the coefficients in multiple parts, as the chip will return a read failure when trying to read all at once over I2C. +#define COEFFICIENT_LENGTH 18 +#define READ_LENGTH (COEFFICIENT_LENGTH / 2) + + uint8_t coef[COEFFICIENT_LENGTH]; + if (!busReadBuf(busDev, DPS310_REG_COEF, coef, READ_LENGTH)) { + return false; + } + if (!busReadBuf(busDev, DPS310_REG_COEF + READ_LENGTH, coef + READ_LENGTH, COEFFICIENT_LENGTH - READ_LENGTH)) { return false; }