1.updata mbed os 5. 2.restore I2C SDA lock low.
Fork of MPU9150_DMP_Nucleo by
Revision 6:9fc30fdfa3c6, committed 2017-06-23
- Comitter:
- tgw
- Date:
- Fri Jun 23 01:18:33 2017 +0000
- Parent:
- 5:20152826993d
- Commit message:
- 1.updata mbed os.; 2.restore I2C SDA lock low.
Changed in this revision
MPU9150.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MPU9150.cpp Sun Mar 29 08:38:25 2015 +0000 +++ b/MPU9150.cpp Fri Jun 23 01:18:33 2017 +0000 @@ -800,11 +800,12 @@ bool MPU9150::write(char reg_addr, char* data, int length) { +/* char reg_addrs[1] = {reg_addr}; char data_w[length]; for(int i=0; i<length; i++) data_w[i] = data[i]; - + i2c.write(device_address<<1, reg_addrs, 1, true); for(int i = 0; i < length; i++) { @@ -817,6 +818,17 @@ } i2c.stop(); return true; +*/ +//-------------------------------------tgw-------------------------------------------- + i2c.start(); + i2c.write(device_address<<1); + i2c.write(reg_addr); + for(int i = 0; i < length; i++) + { + i2c.write(data[i]); + } + i2c.stop(); + return true; } bool MPU9150::writeBit(char reg_addr, uint8_t bit, bool value){ @@ -849,7 +861,7 @@ char command[1]; command[0] = reg_addr; char *redData = (char*)malloc(length); - +/* if(i2c.write(device_address<<1, command, 1, true)) { read_errors ++; @@ -871,6 +883,29 @@ } free (redData); return true; +*/ +//---------------------------------------tgw-------------------------------------------- + if(i2c.write(device_address<<1, command, 1, true)) + { + read_errors ++; + //debug.printf("Read: Address Write Error %d\r\n", reg_addr); + //return false; + } + if(!i2c.read(device_address<<1, redData, length, false)) + { + for(int i =0; i < length; i++) + { + data[i] = redData[i]; + } + } + else + { + read_errors ++; + //debug.printf("Read: Error %d\r\n", reg_addr); + //return false; + } + free (redData); + return true; }