Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: GR-PEACH_test_wo_rtos GR-PEACH_test_on_rtos_works_well Skywire_Demo_3 Skywire_Kinetis_K64_demo ... more
Revision 7:50ac3372def2, committed 2015-12-12
- Comitter:
- kenjiArai
- Date:
- Sat Dec 12 06:06:43 2015 +0000
- Parent:
- 6:e269772dad35
- Child:
- 8:0999d25ed7bc
- Commit message:
- bug fix (divided by 15 & unit mg)
Changed in this revision
| LIS3DH.cpp | Show annotated file Show diff for this revision Revisions of this file |
| LIS3DH.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/LIS3DH.cpp Tue Feb 24 12:24:38 2015 +0000
+++ b/LIS3DH.cpp Sat Dec 12 06:06:43 2015 +0000
@@ -7,7 +7,7 @@
* http://www.page.sannet.ne.jp/kenjia/index.html
* http://mbed.org/users/kenjiArai/
* Created: July 14th, 2014
- * Revised: Feburary 24th, 2015
+ * Revised: December 12th, 2015
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
@@ -110,9 +110,15 @@
}
read_reg_data(data);
// change data type
+#if OLD_REV // Fixed bugs -> (1) unit is not mg but g (2) shift right 4bit = /16
dt_usr[0] = float(short((data[1] << 8) | data[0])) * fs_factor / 15;
dt_usr[1] = float(short((data[3] << 8) | data[2])) * fs_factor / 15;
dt_usr[2] = float(short((data[5] << 8) | data[4])) * fs_factor / 15;
+#else
+ dt_usr[0] = float(short((data[1] << 8) | data[0]) >> 4) * fs_factor;
+ dt_usr[1] = float(short((data[3] << 8) | data[2]) >> 4) * fs_factor;
+ dt_usr[2] = float(short((data[5] << 8) | data[4]) >> 4) * fs_factor;
+#endif
}
void LIS3DH::read_data(float *dt_usr)
@@ -127,9 +133,15 @@
}
read_reg_data(data);
// change data type
+#if OLD_REV // Fixed bugs -> shift right 4bit = /16 (not /15)
dt_usr[0] = float(short((data[1] << 8) | data[0])) * fs_factor / 15 * GRAVITY;
dt_usr[1] = float(short((data[3] << 8) | data[2])) * fs_factor / 15 * GRAVITY;
dt_usr[2] = float(short((data[5] << 8) | data[4])) * fs_factor / 15 * GRAVITY;
+#else
+ dt_usr[0] = float(short((data[1] << 8) | data[0]) >> 4) * fs_factor * GRAVITY;
+ dt_usr[1] = float(short((data[3] << 8) | data[2]) >> 4) * fs_factor * GRAVITY;
+ dt_usr[2] = float(short((data[5] << 8) | data[4]) >> 4) * fs_factor * GRAVITY;
+#endif
}
uint8_t LIS3DH::read_id()
--- a/LIS3DH.h Tue Feb 24 12:24:38 2015 +0000
+++ b/LIS3DH.h Sat Dec 12 06:06:43 2015 +0000
@@ -7,7 +7,7 @@
* http://www.page.sannet.ne.jp/kenjia/index.html
* http://mbed.org/users/kenjiArai/
* Created: July 14th, 2014
- * Revised: Feburary 24th, 2015
+ * Revised: December 12th, 2015
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
@@ -21,6 +21,9 @@
#include "mbed.h"
+// revision 6 have two bugs, (1) read_mg_data, (2) divided by 15 (16 is coorect value)
+#define OLD_REV 0 // KEEP 0!! (If you set 1, work as old revision)
+
// LIS3DH Address
// 7bit address = 0b001100x(0x18 or 0x19 depends on SA0/SDO)
#define LIS3DH_G_CHIP_ADDR (0x18 << 1) // SA0(=SDO pin) = Ground
@@ -48,7 +51,7 @@
#define LIS3DH_CTRL_REG5 0x24
#define LIS3DH_CTRL_REG6 0x25
#define LIS3DH_REFERENCE 0x26
-#define LIS3DH_STATUS_REG2 0x27
+#define LIS3DH_STATUS_REG 0x27
#define LIS3DH_OUT_X_L 0x28
#define LIS3DH_OUT_X_H 0x29
#define LIS3DH_OUT_Y_L 0x2a
@@ -105,13 +108,24 @@
#define LIS3DH_FS_16G 3
// definition for Nomalization
+#if OLD_REV
#define LIS3DH_SENSITIVITY_2G (0.001F)
#define LIS3DH_SENSITIVITY_4G (0.002F)
#define LIS3DH_SENSITIVITY_8G (0.004F)
#define LIS3DH_SENSITIVITY_16G (0.012F)
+#else
+#define LIS3DH_SENSITIVITY_2G 1
+#define LIS3DH_SENSITIVITY_4G 2
+#define LIS3DH_SENSITIVITY_8G 4
+#define LIS3DH_SENSITIVITY_16G 12
+#endif
//Gravity at Earth's surface in m/s/s
+#if OLD_REV
#define GRAVITY (9.80665F)
+#else
+#define GRAVITY (9.80665F / 1000)
+#endif
/** Interface for STMicronics MEMS motion sensor: 3-axis "nano" accelerometer
* Chip: LIS3DH
@@ -223,7 +237,11 @@
I2C _i2c;
private:
+#if OLD_REV
float fs_factor; // full scale factor
+#else
+ uint8_t fs_factor; // full scale factor
+#endif
char dt[2]; // working buffer
uint8_t acc_addr; // acc sensor address
uint8_t acc_id; // acc ID