Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: I2Cdev.cpp
- Revision:
- 6:fe57b4405983
- Parent:
- 2:f8bfb37b2e1f
--- a/I2Cdev.cpp Sat Nov 23 16:47:00 2013 +0000
+++ b/I2Cdev.cpp Wed Oct 25 08:08:53 2017 +0000
@@ -5,7 +5,7 @@
#include "I2Cdev.h"
-#define useDebugSerial
+//#define useDebugSerial
I2Cdev::I2Cdev(): i2c(I2C_SDA,I2C_SCL), debugSerial(USBTX, USBRX)
{
@@ -254,14 +254,15 @@
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]);
+ char *writeData = (char*)malloc(length+1);
+ writeData[0] = regAddr;
+
+ for(int i=0; i<length ; i++){
+ writeData[i+1] = data[i];
}
- i2c.stop();
- return true;
+ int res = i2c.write(devAddr<<1, writeData, length+1, true);
+ free(writeData);
+ return res;
}
bool I2Cdev::writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data)