Skip to content

Commit df9b18f

Browse files
authored
Merge pull request #10423 from ultrazar/patch-1
Added IMUTemperature read function for ICM42605
2 parents 78e1392 + a3afa3f commit df9b18f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/main/drivers/accgyro/accgyro_icm42605.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262

6363
#define ICM42605_RA_GYRO_DATA_X1 0x25
6464
#define ICM42605_RA_ACCEL_DATA_X1 0x1F
65+
#define ICM42605_RA_TEMP_DATA1 0x1D
6566

6667
#define ICM42605_RA_INT_CONFIG 0x14
6768
#define ICM42605_INT1_MODE_PULSED (0 << 2)
@@ -321,6 +322,20 @@ static bool icm42605GyroRead(gyroDev_t *gyro)
321322
return true;
322323
}
323324

325+
static bool icm42605ReadTemperature(gyroDev_t *gyro, int16_t * temp)
326+
{
327+
uint8_t data[2];
328+
329+
const bool ack = busReadBuf(gyro->busDev, ICM42605_RA_TEMP_DATA1, data, 2);
330+
if (!ack) {
331+
return false;
332+
}
333+
// From datasheet: Temperature in Degrees Centigrade = (TEMP_DATA / 132.48) + 25
334+
*temp = ( int16_val_big_endian(data, 0) / 13.248 ) + 250; // Temperature stored as degC*10
335+
336+
return true;
337+
}
338+
324339
bool icm42605GyroDetect(gyroDev_t *gyro)
325340
{
326341
gyro->busDev = busDeviceInit(BUSTYPE_ANY, DEVHW_ICM42605, gyro->imuSensorToUse, OWNER_MPU);
@@ -340,7 +355,7 @@ bool icm42605GyroDetect(gyroDev_t *gyro)
340355
gyro->initFn = icm42605AccAndGyroInit;
341356
gyro->readFn = icm42605GyroRead;
342357
gyro->intStatusFn = gyroCheckDataReady;
343-
gyro->temperatureFn = NULL;
358+
gyro->temperatureFn = icm42605ReadTemperature;
344359
gyro->scale = 1.0f / 16.4f; // 16.4 dps/lsb scalefactor
345360
gyro->gyroAlign = gyro->busDev->param;
346361

0 commit comments

Comments
 (0)