bmm150: more explicit data conversion & reduce to 30Hz

- 30Hz is the sensors max update rate in continous mode
  (though not in forced mode as we are using it)
- 30Hz allows to increase the quality of the measurements
This commit is contained in:
Beat Küng
2020-05-06 09:09:00 +02:00
committed by Daniel Agar
parent b5e25c2218
commit 1175c08829
2 changed files with 14 additions and 14 deletions
+12 -12
View File
@@ -228,29 +228,29 @@ int BMM150::collect()
*/ */
/* Extract X axis data */ /* Extract X axis data */
lsb = ((mag_data[0] & 0xF8) >> 3); lsb = ((mag_data[0] & 0xF8));
msb = (((int8_t)mag_data[1]) << 5); msb = ((uint16_t)(mag_data[1]) << 8);
msblsb = (msb | lsb); msblsb = (msb | lsb);
x_raw = (int16_t)msblsb; x_raw = (int16_t)msblsb / 8;
/* Extract Y axis data */ /* Extract Y axis data */
lsb = ((mag_data[2] & 0xF8) >> 3); lsb = ((mag_data[2] & 0xF8));
msb = (((int8_t)mag_data[3]) << 5); msb = (((uint16_t)(mag_data[3])) << 8);
msblsb = (msb | lsb); msblsb = (msb | lsb);
y_raw = (int16_t)msblsb; y_raw = (int16_t)msblsb / 8;
/* Extract Z axis data */ /* Extract Z axis data */
lsb = ((mag_data[4] & 0xFE) >> 1); lsb = ((mag_data[4] & 0xFE));
msb = (((int8_t)mag_data[5]) << 7); msb = (((uint16_t)(mag_data[5])) << 8);
msblsb = (msb | lsb); msblsb = (msb | lsb);
z_raw = (int16_t)msblsb; z_raw = (int16_t)msblsb / 2;
/* Extract Resistance data */ /* Extract Resistance data */
lsb = ((mag_data[6] & 0xFC) >> 2); lsb = ((mag_data[6] & 0xFC));
msb = (mag_data[7] << 6); msb = (((uint16_t)mag_data[7]) << 8);
msblsb = (msb | lsb); msblsb = (msb | lsb);
resistance = (uint16_t)msblsb; resistance = (uint16_t)msblsb / 4;
/* Check whether data is new or old */ /* Check whether data is new or old */
if (!(status & 0x01)) { if (!(status & 0x01)) {
+2 -2
View File
@@ -145,7 +145,7 @@
#define BMM150_DEFAULT_ODR BMM150_DATA_RATE_30HZ #define BMM150_DEFAULT_ODR BMM150_DATA_RATE_30HZ
/* Maximum output data rate */ /* Maximum output data rate */
#define BMM150_MAX_DATA_RATE 100 #define BMM150_MAX_DATA_RATE 30
/* Default BMM150_INT_SETT_CTRL_REG Value */ /* Default BMM150_INT_SETT_CTRL_REG Value */
#define BMM150_DEFAULT_INT_SETT 0x3F #define BMM150_DEFAULT_INT_SETT 0x3F
@@ -181,7 +181,7 @@
#define BMM150_SOFT_RESET_MASK 0x82 #define BMM150_SOFT_RESET_MASK 0x82
/* This value is set based on Max output data rate value */ /* This value is set based on Max output data rate value */
#define BMM150_CONVERSION_INTERVAL (1000000 / 100) /* microseconds */ #define BMM150_CONVERSION_INTERVAL (1000000 / BMM150_MAX_DATA_RATE) /* microseconds */
struct bmm150_data { struct bmm150_data {
int16_t x; int16_t x;