ddwdwdrr

Fork of MPU6050 by Simon Garfieldsg

Files at this revision

API Documentation at this revision

Comitter:
antoine4375
Date:
Wed Oct 07 12:23:32 2015 +0000
Parent:
2:1215907c700d
Commit message:
dddd

Changed in this revision

I2Cdev.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/I2Cdev.cpp	Wed Oct 07 06:58:05 2015 +0000
+++ b/I2Cdev.cpp	Wed Oct 07 12:23:32 2015 +0000
@@ -129,6 +129,8 @@
  */
 int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout)
 {
+    /*
+    // I don't know why not work if i use this code. maybe malloc problem?
     char command[1];
     command[0] = regAddr;
     char *redData = (char*)malloc(length);
@@ -138,6 +140,10 @@
         data[i] = redData[i];
     }
     return length;
+    */
+    i2c.write(devAddr<<1, (char*)&regAddr, sizeof(regAddr), true);
+    i2c.read(devAddr<<1, (char*)data, length);
+    return length;
 }
 
 int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout)