From 70681f990f16ef82cdb0ad7163247e8fdd3306a8 Mon Sep 17 00:00:00 2001 From: Dennis Millard <49655137+dmillard-TD@users.noreply.github.com> Date: Tue, 16 Apr 2019 20:53:16 -0600 Subject: [PATCH] BMI055 IMU driver fix temperature reporting --- src/drivers/imu/bmi055/BMI055_accel.cpp | 18 +++++++++++------- src/drivers/imu/bmi055/BMI055_gyro.cpp | 9 +++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/drivers/imu/bmi055/BMI055_accel.cpp b/src/drivers/imu/bmi055/BMI055_accel.cpp index 3a8820e4cc..bc3e2c1beb 100644 --- a/src/drivers/imu/bmi055/BMI055_accel.cpp +++ b/src/drivers/imu/bmi055/BMI055_accel.cpp @@ -510,7 +510,7 @@ BMI055_accel::measure() { perf_count(_measure_interval); - uint8_t index = 0, accel_data[7]; + uint8_t index = 0, accel_data[8]; uint16_t lsb, msb, msblsb; uint8_t status_x, status_y, status_z; @@ -523,7 +523,7 @@ BMI055_accel::measure() int16_t accel_x; int16_t accel_y; int16_t accel_z; - int16_t temp; + int8_t temp; } report; /* start measuring */ @@ -560,6 +560,9 @@ BMI055_accel::measure() msblsb = (msb << 8) | lsb; report.accel_z = ((int16_t)msblsb >> 4); /* Data in Z axis */ + // Byte + report.temp = accel_data[index]; + // Checking the status of new data if ((!status_x) || (!status_y) || (!status_z)) { perf_end(_sample_perf); @@ -571,9 +574,6 @@ BMI055_accel::measure() _got_duplicate = false; - uint8_t temp = read_reg(BMI055_ACC_TEMP); - report.temp = temp; - if (report.accel_x == 0 && report.accel_y == 0 && report.accel_z == 0 && @@ -649,9 +649,13 @@ BMI055_accel::measure() arb.scaling = _accel_range_scale; - _last_temperature = 23 + report.temp * 1.0f / 512.0f; - + /* + * Temperature is reported as Eight-bit 2’s complement sensor temperature value + * with 0.5 °C/LSB sensitivity and an offset of 23.0 °C + */ + _last_temperature = (report.temp * 0.5f) + 23.0f; arb.temperature = _last_temperature; + arb.device_id = _device_id.devid; _accel_reports->force(&arb); diff --git a/src/drivers/imu/bmi055/BMI055_gyro.cpp b/src/drivers/imu/bmi055/BMI055_gyro.cpp index 275dba833d..aecb0ff6cd 100644 --- a/src/drivers/imu/bmi055/BMI055_gyro.cpp +++ b/src/drivers/imu/bmi055/BMI055_gyro.cpp @@ -562,8 +562,7 @@ BMI055_gyro::measure() check_registers(); - uint8_t temp = read_reg(BMI055_ACC_TEMP); - + int8_t temp = read_reg(BMI055_ACC_TEMP); report.temp = temp; report.gyro_x = bmi_gyroreport.gyro_x; @@ -648,7 +647,13 @@ BMI055_gyro::measure() grb.scaling = _gyro_range_scale; + /* + * Temperature is reported as Eight-bit 2’s complement sensor temperature value + * with 0.5 °C/LSB sensitivity and an offset of 23.0 °C + */ + _last_temperature = (report.temp * 0.5f) + 23.0f; grb.temperature = _last_temperature; + grb.device_id = _device_id.devid; _gyro_reports->force(&grb); -- GitLab