Ported from Arduino Library : https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050

Dependents:   kopija_NUCLEO_CELL_LOCKER_copy

Fork of MPU6050 by Simon Garfieldsg

Revision:
2:e2081d9de7af
Parent:
1:1e0baaf91e96
Child:
3:b21c8c3456be
diff -r 1e0baaf91e96 -r e2081d9de7af I2Cdev.cpp
--- a/I2Cdev.cpp	Wed May 08 00:34:55 2013 +0000
+++ b/I2Cdev.cpp	Wed Feb 01 11:09:14 2017 +0000
@@ -7,12 +7,12 @@
 
 #define useDebugSerial
 
-I2Cdev::I2Cdev(): debugSerial(USBTX, USBRX), i2c(I2C_SDA,I2C_SCL)
+I2Cdev::I2Cdev(): debugSerial(p6, p8), i2c(p26,p27)
 {
 
 }
 
-I2Cdev::I2Cdev(PinName i2cSda, PinName i2cScl): debugSerial(USBTX, USBRX), i2c(i2cSda,i2cScl)
+I2Cdev::I2Cdev(PinName p26, PinName p27): debugSerial(p30, p31), i2c(p26,p27)
 {
 
 }
@@ -46,7 +46,9 @@
     *data = b & (1 << bitNum);
     return count;
 }
-
+void I2Cdev::frequency(uint8_t freq){
+    i2c.frequency(freq);
+    }
 /** Read multiple bits from an 8-bit device register.
  * @param devAddr I2C slave device address
  * @param regAddr Register regAddr to read from
@@ -239,7 +241,15 @@
  * @return Status of operation (true = success)
  */
 bool I2Cdev::writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data) {
-    return writeBytes(devAddr, regAddr, 1, &data);
+    devAddr=0xd0;
+    //pc.printf("| Address: %x | Register: %x \r\n",devAddr,regAddr);
+ 
+    char data_write[2];
+    data_write[0]=regAddr;           // I2C sends MSB first. Namely  >>|subAddress|>>|data|
+    data_write[1]=data;
+    i2c.write(devAddr,data_write,2,0);  // i2c.write(int address, char* data, int length, bool repeated=false);  
+    //return writeBytes(devAddr, regAddr, 1, &data);
+    return true;
 }
 
 /** Write single word to a 16-bit device register.
@@ -255,11 +265,12 @@
 bool I2Cdev::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data)
 {
     i2c.start();
-    i2c.write(devAddr<<1);
-    i2c.write(regAddr);
-    for(int i = 0; i < length; i++) {
-        i2c.write(data[i]);
-    }
+    //i2c.write(devAddr<<1);
+    //i2c.write(regAddr);
+    //for(int i = 0; i < length; i++) {
+    //    i2c.write(data[i]);
+    //}
+    //i2c.write(devAddr, regAddr, )
     i2c.stop();
     return true;
 }