From 60c9521da6072e6c891bd30fd772e91a790f0b53 Mon Sep 17 00:00:00 2001 From: Steve Evans Date: Mon, 21 Nov 2022 23:22:21 +0000 Subject: [PATCH] Fix read of DPS310 coef C11 (#12011) --- src/main/drivers/barometer/barometer_dps310.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/drivers/barometer/barometer_dps310.c b/src/main/drivers/barometer/barometer_dps310.c index df7958d2f..1918053ec 100644 --- a/src/main/drivers/barometer/barometer_dps310.c +++ b/src/main/drivers/barometer/barometer_dps310.c @@ -24,6 +24,8 @@ * Copyright: INAVFLIGHT OU */ +// See datasheet at https://www.infineon.com/dgdl/Infineon-DPS310-DataSheet-v01_02-EN.pdf?fileId=5546d462576f34750157750826c42242 + #include #include #include @@ -179,6 +181,8 @@ static bool deviceConfigure(const extDevice_t *dev) return false; } + // See section 8.11, Calibration Coefficients (COEF), of datasheet + // 0x11 c0 [3:0] + 0x10 c0 [11:4] baroState.calib.c0 = getTwosComplement(((uint32_t)coef[0] << 4) | (((uint32_t)coef[1] >> 4) & 0x0F), 12); @@ -195,7 +199,7 @@ static bool deviceConfigure(const extDevice_t *dev) baroState.calib.c01 = getTwosComplement(((uint32_t)coef[8] << 8) | (uint32_t)coef[9], 16); // 0x1A c11 [15:8] + 0x1B c11 [7:0] - baroState.calib.c11 = getTwosComplement(((uint32_t)coef[8] << 8) | (uint32_t)coef[9], 16); + baroState.calib.c11 = getTwosComplement(((uint32_t)coef[10] << 8) | (uint32_t)coef[11], 16); // 0x1C c20 [15:8] + 0x1D c20 [7:0] baroState.calib.c20 = getTwosComplement(((uint32_t)coef[12] << 8) | (uint32_t)coef[13], 16); @@ -263,10 +267,13 @@ static bool dps310GetUP(baroDev_t *baro) const float c21 = baroState.calib.c21; const float c30 = baroState.calib.c30; + // See section 4.9.1, How to Calculate Compensated Pressure Values, of datasheet + baroState.pressure = c00 + Praw_sc * (c10 + Praw_sc * (c20 + Praw_sc * c30)) + Traw_sc * c01 + Traw_sc * Praw_sc * (c11 + Praw_sc * c21); + const float c0 = baroState.calib.c0; const float c1 = baroState.calib.c1; - baroState.pressure = c00 + Praw_sc * (c10 + Praw_sc * (c20 + Praw_sc * c30)) + Traw_sc * c01 + Traw_sc * Praw_sc * (c11 + Praw_sc * c21); + // See section 4.9.2, How to Calculate Compensated Temperature Values, of datasheet baroState.temperature = c0 * 0.5f + c1 * Traw_sc; return true; -- 2.11.4.GIT