Modified MPU9150 Library for Nucleo F303K8
Fork of MPU9150_DMP by
Revision 3:ed487dfe5570, committed 2016-05-14
- Comitter:
- yishii
- Date:
- Sat May 14 07:11:27 2016 +0000
- Parent:
- 2:e523a92390b6
- Commit message:
- Supported to use sensor with Nucleo F3030K8
Changed in this revision
MPU9150.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MPU9150.cpp Mon Sep 01 14:25:06 2014 +0000 +++ b/MPU9150.cpp Sat May 14 07:11:27 2016 +0000 @@ -27,6 +27,7 @@ =============================================== */ +extern Serial pc; uint8_t MPU9150::getDeviceID(){ uint8_t ret = 0; @@ -35,7 +36,10 @@ } bool MPU9150::isReady(){ - return (getDeviceID() == (device_address >> 1)); + //pc.printf("GetDeviceID = %02Xh, expected = %02Xh\r\n",getDeviceID(),(device_address >> 1)); + //return (getDeviceID() == (device_address >> 1)); + //pc.printf("GetDeviceID = %02Xh, expected = %02Xh\r\n",getDeviceID(),0x71>>1); + return (getDeviceID() == 0x71>>1); } void MPU9150::initialise(){ @@ -790,19 +794,32 @@ return write(reg_addr, &data, 1); } +uint8_t write_buff[32]; + bool MPU9150::write(char reg_addr, char* data, int length){ +#if 0 i2c.start(); i2c.write(device_address << 1); i2c.write(reg_addr); for(int i = 0; i < length; i++) { if(!i2c.write(data[i])){ write_errors++; - //debug.printf("Write Error %d\r\n", reg_addr); + pc.printf("Write Error %02X\r\n", reg_addr); return false; } } i2c.stop(); return true; +#else + if(length > 31){ + printf("err! in MPU9150::write\r\n"); + } + write_buff[0] = reg_addr; + memcpy(&(write_buff[1]),data,length); + i2c.write(char(device_address << 1), (char*) write_buff, length + 1); + + return true; +#endif } bool MPU9150::writeBit(char reg_addr, uint8_t bit, bool value){ @@ -827,18 +844,20 @@ } bool MPU9150::read(char reg_addr, char* data){ - return read(reg_addr, data, 1); + bool result = read(reg_addr, data, 1); + return result; } bool MPU9150::read(char reg_addr, char* data, int length){ + //pc.printf("device address = %02Xh\r\n", device_address << 1 ); if(i2c.write(device_address << 1, ®_addr, 1, true)){ read_errors ++; - //debug.printf("Read: Address Write Error %d\r\n", reg_addr); + //pc.printf("Read: Address Write Error %d\r\n", reg_addr); return false; } if(i2c.read(device_address << 1, data, length)){ read_errors ++; - //debug.printf("Read: Error %d\r\n", reg_addr); + //pc.printf("Read: Error %d\r\n", reg_addr); return false; } return true;