Library to communicate with a ST LIS331DLH

Files at this revision

API Documentation at this revision

Comitter:
atommota
Date:
Tue Jun 17 19:31:05 2014 +0000
Parent:
8:ff365f926a52
Child:
10:dcd11c84305e
Commit message:
Patch to correctly auto increment read registers

Changed in this revision

LIS331.cpp Show annotated file Show diff for this revision Revisions of this file
LIS331.h Show annotated file Show diff for this revision Revisions of this file
--- a/LIS331.cpp	Fri Jul 01 21:07:25 2011 +0000
+++ b/LIS331.cpp	Tue Jun 17 19:31:05 2014 +0000
@@ -114,11 +114,10 @@
 void LIS331::setFullScaleRange8g(void){  // Does not preserve rest of CTRL_REG_4!
     scaling_factor = 4096.0;
     current_range = 8;
-
     char tx[2];
     tx[0] = CTRL_REG_4;
     tx[1] = 0x30;
-        
+    
     i2c_.write((LIS331_I2C_ADDRESS << 1) & 0xFE, tx, 2);
     
 }
@@ -165,7 +164,7 @@
 
 float LIS331::getAccelX(void){
 
-    char tx = ACCEL_XOUT_H_REG;
+    char tx = ACCEL_XOUT_L_REG | 0x80;
     char rx[2];
     
     i2c_.write((LIS331_I2C_ADDRESS << 1) & 0xFE, &tx, 1);
@@ -180,7 +179,7 @@
 
 float LIS331::getAccelY(void){
 
-    char tx = ACCEL_YOUT_H_REG;
+    char tx = ACCEL_YOUT_L_REG | 0x80;
     char rx[2];
     
     i2c_.write((LIS331_I2C_ADDRESS << 1) & 0xFE, &tx, 1);
@@ -193,9 +192,9 @@
 
 }
 
-float LIS331::getAccelZ(void){
+int LIS331::getAccelZ(void){
 
-    char tx = ACCEL_ZOUT_H_REG;
+    char tx = ACCEL_ZOUT_L_REG | 0x80;
     char rx[2];
     
     i2c_.write((LIS331_I2C_ADDRESS << 1) & 0xFE, &tx, 1);
@@ -205,4 +204,5 @@
     int16_t output = ((int) rx[0] << 8) | ((int) rx[1]);
 
     return output/scaling_factor;
+
 }
\ No newline at end of file
--- a/LIS331.h	Fri Jul 01 21:07:25 2011 +0000
+++ b/LIS331.h	Tue Jun 17 19:31:05 2014 +0000
@@ -165,7 +165,7 @@
      *
      */
      
-     
+  
     /**
      * Set the Full Scale Range to +/- 8g's.
      *
@@ -209,7 +209,7 @@
      * 
      * @return The output on the z-axis in engineering units (g's).
      */
-    float getAccelZ(void);
+    int getAccelZ(void);
 
    
 private: