LSM9DS1 IMU sensor driver

Dependents:   LSM_imu Izu_2019

Files at this revision

API Documentation at this revision

Comitter:
zeutel
Date:
Sat Mar 02 15:15:14 2019 +0000
Parent:
1:0e76f237c23d
Commit message:
LSM9DS1

Changed in this revision

LSM9DS1.cpp Show annotated file Show diff for this revision Revisions of this file
LSM9DS1.h Show annotated file Show diff for this revision Revisions of this file
diff -r 0e76f237c23d -r 2ba419ea901e LSM9DS1.cpp
--- a/LSM9DS1.cpp	Mon Oct 19 13:56:52 2015 +0000
+++ b/LSM9DS1.cpp	Sat Mar 02 15:15:14 2019 +0000
@@ -398,4 +398,30 @@
             mRes = 16.0 / 32768.0;
             break;
     }
+}
+
+bool LSM9DS1::whoAmI(){
+    uint8_t resultXG,resultM ,whoAmIAddressXG=WHO_AM_I_XG,whoAmIAddressM=WHO_AM_I_M;
+    
+    //acc gyro
+    i2c.start();
+    i2c.write(xgAddress);
+    i2c.write(whoAmIAddressXG);
+    i2c.write(xgAddress | 1);
+    resultXG = i2c.read(whoAmIAddressXG);
+    i2c.stop();
+    
+    //magn
+    i2c.start();
+    i2c.write(xgAddress);
+    i2c.write(whoAmIAddressM);
+    i2c.write(xgAddress | 1);
+    resultM = i2c.read(whoAmIAddressM);
+    i2c.stop();
+    
+    uint16_t combinedResult = (resultXG << 8) | resultM;
+    if(combinedResult!=((whoAmIAddressXG << 8) | whoAmIAddressM))
+        return true;
+    else
+        return false;
 }
\ No newline at end of file
diff -r 0e76f237c23d -r 2ba419ea901e LSM9DS1.h
--- a/LSM9DS1.h	Mon Oct 19 13:56:52 2015 +0000
+++ b/LSM9DS1.h	Sat Mar 02 15:15:14 2019 +0000
@@ -315,6 +315,7 @@
     */
     void setMagODR(mag_odr mRate);
 
+    bool whoAmI();
 
 private:    
     /**  xgAddress and mAddress store the I2C address