Skip to content

Commit 60c9521

Browse files
authored
Fix read of DPS310 coef C11 (#12011)
1 parent 55cd978 commit 60c9521

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/main/drivers/barometer/barometer_dps310.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
* Copyright: INAVFLIGHT OU
2525
*/
2626

27+
// See datasheet at https://www.infineon.com/dgdl/Infineon-DPS310-DataSheet-v01_02-EN.pdf?fileId=5546d462576f34750157750826c42242
28+
2729
#include <stdbool.h>
2830
#include <stdint.h>
2931
#include <string.h>
@@ -179,6 +181,8 @@ static bool deviceConfigure(const extDevice_t *dev)
179181
return false;
180182
}
181183

184+
// See section 8.11, Calibration Coefficients (COEF), of datasheet
185+
182186
// 0x11 c0 [3:0] + 0x10 c0 [11:4]
183187
baroState.calib.c0 = getTwosComplement(((uint32_t)coef[0] << 4) | (((uint32_t)coef[1] >> 4) & 0x0F), 12);
184188

@@ -195,7 +199,7 @@ static bool deviceConfigure(const extDevice_t *dev)
195199
baroState.calib.c01 = getTwosComplement(((uint32_t)coef[8] << 8) | (uint32_t)coef[9], 16);
196200

197201
// 0x1A c11 [15:8] + 0x1B c11 [7:0]
198-
baroState.calib.c11 = getTwosComplement(((uint32_t)coef[8] << 8) | (uint32_t)coef[9], 16);
202+
baroState.calib.c11 = getTwosComplement(((uint32_t)coef[10] << 8) | (uint32_t)coef[11], 16);
199203

200204
// 0x1C c20 [15:8] + 0x1D c20 [7:0]
201205
baroState.calib.c20 = getTwosComplement(((uint32_t)coef[12] << 8) | (uint32_t)coef[13], 16);
@@ -263,10 +267,13 @@ static bool dps310GetUP(baroDev_t *baro)
263267
const float c21 = baroState.calib.c21;
264268
const float c30 = baroState.calib.c30;
265269

270+
// See section 4.9.1, How to Calculate Compensated Pressure Values, of datasheet
271+
baroState.pressure = c00 + Praw_sc * (c10 + Praw_sc * (c20 + Praw_sc * c30)) + Traw_sc * c01 + Traw_sc * Praw_sc * (c11 + Praw_sc * c21);
272+
266273
const float c0 = baroState.calib.c0;
267274
const float c1 = baroState.calib.c1;
268275

269-
baroState.pressure = c00 + Praw_sc * (c10 + Praw_sc * (c20 + Praw_sc * c30)) + Traw_sc * c01 + Traw_sc * Praw_sc * (c11 + Praw_sc * c21);
276+
// See section 4.9.2, How to Calculate Compensated Temperature Values, of datasheet
270277
baroState.temperature = c0 * 0.5f + c1 * Traw_sc;
271278

272279
return true;

0 commit comments

Comments
 (0)