For nucleoF103 change sda,scl to PB_7,PB_6
Dependents: AGV_0411 AGV_SMT_Sevro AGV_SMT
Fork of MPU6050-DMP by
Diff: I2Cdev.cpp
- Revision:
- 8:473800bd51ac
- Parent:
- 6:fe57b4405983
diff -r 6b1b4bcaf494 -r 473800bd51ac I2Cdev.cpp --- a/I2Cdev.cpp Thu Apr 12 01:11:08 2018 +0000 +++ b/I2Cdev.cpp Thu May 10 08:15:44 2018 +0000 @@ -1,20 +1,18 @@ // ported from arduino library: https://github.com/jrowberg/i2cdevlib // written by szymon gaertig (email: szymon@gaertig.com.pl, website: szymongaertig.pl) +// modified by shundo kishi +// // Changelog: // 2013-01-08 - first release +// 2016-01-31 - changed all functions and variables static to make porting from arduino easier(by shundo kishi) #include "I2Cdev.h" -//#define useDebugSerial - -I2Cdev::I2Cdev(): i2c(I2C_SDA,I2C_SCL), debugSerial(USBTX, USBRX) -{ +I2C I2Cdev::i2c(I2C_SDA,I2C_SCL); -} - -I2Cdev::I2Cdev(PinName i2cSda, PinName i2cScl): i2c(i2cSda,i2cScl), debugSerial(USBTX, USBRX) -{ - +/** Default constructor. + */ +I2Cdev::I2Cdev() { } /** Read a single bit from an 8-bit device register. @@ -254,15 +252,14 @@ bool I2Cdev::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data) { - char *writeData = (char*)malloc(length+1); - writeData[0] = regAddr; - - for(int i=0; i<length ; i++){ - writeData[i+1] = data[i]; + i2c.start(); + i2c.write(devAddr<<1); + i2c.write(regAddr); + for(int i = 0; i < length; i++) { + i2c.write(data[i]); } - int res = i2c.write(devAddr<<1, writeData, length+1, true); - free(writeData); - return res; + i2c.stop(); + return true; } bool I2Cdev::writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data)