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.
Diff: LIS331.cpp
- Revision:
- 9:5af73355984f
- Parent:
- 8:ff365f926a52
- Child:
- 10:dcd11c84305e
diff -r ff365f926a52 -r 5af73355984f LIS331.cpp
--- 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