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: I2cPeripherals/I2cPeripherals.cpp
- Revision:
- 3:27407c4984cf
- Parent:
- 2:59ac9df97701
- Child:
- 4:4060309b9cc0
--- a/I2cPeripherals/I2cPeripherals.cpp Fri Nov 15 20:53:36 2013 +0000
+++ b/I2cPeripherals/I2cPeripherals.cpp Thu Feb 13 16:07:07 2014 +0000
@@ -4,7 +4,7 @@
I2cPeripherals::I2cPeripherals(PinName sda, PinName scl): _i2c(sda,scl)
{
- _i2c.frequency(400000);
+ _i2c.frequency(200000);
// LCD_contrast = 60;
wait(0.5);
LCD_addr = 0;
@@ -125,7 +125,7 @@
_i2c.write(sens[num].addr,tx,2);
wait(0.01);
tx[0] = 0x1C;
- tx[1] = 0x18; // +-16g
+ tx[1] = 0x18; // 00:2g,08:4g,10:8g,18:+-16g
_i2c.write(sens[num].addr,tx,2);
wait_ms(10);
break;
@@ -272,6 +272,7 @@
//AXDL345 Data Read
char rx[6];
char tx[1];
+ float lsb;
tx[0] = Accel_data | 0x80;
if ( _i2c.write(Accel_addr,tx,1,true) != 0 ) {
*x=*y=0;
@@ -283,9 +284,11 @@
case 0xD0:
case 0xD2:
#ifdef MPU6050
- *y = ( -(short(rx[0] << 8 | (uint8_t)rx[1])) ) * 0.0048;
- *x = ( short(rx[2] << 8 | (uint8_t)rx[3]) ) * 0.0048;
- *z = ( short(rx[4] << 8 | (uint8_t)rx[5]) ) * 0.0048;
+ lsb = 0.000488; //16g
+// lsb = 0.000122; //4g
+ *y = ( -(short(rx[0] << 8 | (uint8_t)rx[1])) ) * lsb;
+ *x = ( short(rx[2] << 8 | (uint8_t)rx[3]) ) * lsb;
+ *z = ( short(rx[4] << 8 | (uint8_t)rx[5]) ) * lsb;
#endif
break;
case 0xA6:
@@ -294,6 +297,7 @@
*y = ( -(short(rx[1] << 8 | (uint8_t)rx[0])) ) * 0.04;
*x = ( short(rx[3] << 8 | (uint8_t)rx[2]) ) * 0.04;
*z = ( short(rx[5] << 8 | (uint8_t)rx[4]) ) * 0.04;
+ break;
#endif
}
return true;