diff --git a/Arduino/I2Cdev/I2Cdev.cpp b/Arduino/I2Cdev/I2Cdev.cpp index 892274ba..233e4099 100644 --- a/Arduino/I2Cdev/I2Cdev.cpp +++ b/Arduino/I2Cdev/I2Cdev.cpp @@ -234,9 +234,7 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 useWire->beginTransmission(devAddr); useWire->send(regAddr); useWire->endTransmission(); - useWire->beginTransmission(devAddr); useWire->requestFrom((uint8_t)devAddr, (uint8_t)min((int)length - k, I2CDEVLIB_WIRE_BUFFER_LENGTH)); - for (; useWire->available() && (timeout == 0 || millis() - t1 < timeout); count++) { data[count] = useWire->receive(); #ifdef I2CDEV_SERIAL_DEBUG @@ -244,8 +242,6 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 if (count + 1 < length) Serial.print(" "); #endif } - - useWire->endTransmission(); } #elif (ARDUINO == 100) // Arduino v1.0.0, Wire library @@ -258,9 +254,7 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 useWire->beginTransmission(devAddr); useWire->write(regAddr); useWire->endTransmission(); - useWire->beginTransmission(devAddr); useWire->requestFrom((uint8_t)devAddr, (uint8_t)min((int)length - k, I2CDEVLIB_WIRE_BUFFER_LENGTH)); - for (; useWire->available() && (timeout == 0 || millis() - t1 < timeout); count++) { data[count] = useWire->read(); #ifdef I2CDEV_SERIAL_DEBUG @@ -268,8 +262,6 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 if (count + 1 < length) Serial.print(" "); #endif } - - useWire->endTransmission(); } #elif (ARDUINO > 100) // Arduino v1.0.1+, Wire library @@ -282,9 +274,7 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 useWire->beginTransmission(devAddr); useWire->write(regAddr); useWire->endTransmission(); - useWire->beginTransmission(devAddr); useWire->requestFrom((uint8_t)devAddr, (uint8_t)min((int)length - k, I2CDEVLIB_WIRE_BUFFER_LENGTH)); - for (; useWire->available() && (timeout == 0 || millis() - t1 < timeout); count++) { data[count] = useWire->read(); #ifdef I2CDEV_SERIAL_DEBUG @@ -356,7 +346,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 useWire->beginTransmission(devAddr); useWire->send(regAddr); useWire->endTransmission(); - useWire->beginTransmission(devAddr); useWire->requestFrom(devAddr, (uint8_t)(length * 2)); // length=words, this wants bytes bool msb = true; // starts with MSB, then LSB @@ -375,8 +364,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 } msb = !msb; } - - useWire->endTransmission(); } #elif (ARDUINO == 100) // Arduino v1.0.0, Wire library @@ -389,7 +376,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 useWire->beginTransmission(devAddr); useWire->write(regAddr); useWire->endTransmission(); - useWire->beginTransmission(devAddr); useWire->requestFrom(devAddr, (uint8_t)(length * 2)); // length=words, this wants bytes bool msb = true; // starts with MSB, then LSB @@ -408,8 +394,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 } msb = !msb; } - - useWire->endTransmission(); } #elif (ARDUINO > 100) // Arduino v1.0.1+, Wire library @@ -422,7 +406,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 useWire->beginTransmission(devAddr); useWire->write(regAddr); useWire->endTransmission(); - useWire->beginTransmission(devAddr); useWire->requestFrom(devAddr, (uint8_t)(length * 2)); // length=words, this wants bytes bool msb = true; // starts with MSB, then LSB @@ -441,8 +424,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 } msb = !msb; } - - useWire->endTransmission(); } #endif diff --git a/MSP430/I2Cdev/I2Cdev.cpp b/MSP430/I2Cdev/I2Cdev.cpp index 7613b70e..6e539f79 100644 --- a/MSP430/I2Cdev/I2Cdev.cpp +++ b/MSP430/I2Cdev/I2Cdev.cpp @@ -230,9 +230,7 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 Wire.beginTransmission(devAddr); Wire.send(regAddr); Wire.endTransmission(); - Wire.beginTransmission(devAddr); Wire.requestFrom(devAddr, (uint8_t)min(length - k, I2CDEVLIB_WIRE_BUFFER_LENGTH)); - for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) { data[count] = Wire.receive(); #ifdef I2CDEV_SERIAL_DEBUG @@ -240,8 +238,6 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 if (count + 1 < length) Serial.print(" "); #endif } - - Wire.endTransmission(); } #elif (ARDUINO == 100) // Arduino v1.0.0, Wire library @@ -254,9 +250,7 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 Wire.beginTransmission(devAddr); Wire.write(regAddr); Wire.endTransmission(); - Wire.beginTransmission(devAddr); Wire.requestFrom(devAddr, (uint8_t)min(length - k, I2CDEVLIB_WIRE_BUFFER_LENGTH)); - for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) { data[count] = Wire.read(); #ifdef I2CDEV_SERIAL_DEBUG @@ -264,8 +258,6 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 if (count + 1 < length) Serial.print(" "); #endif } - - Wire.endTransmission(); } #elif (ARDUINO > 100) // Arduino v1.0.1+, Wire library @@ -278,9 +270,7 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 Wire.beginTransmission(devAddr); Wire.write(regAddr); Wire.endTransmission(); - Wire.beginTransmission(devAddr); Wire.requestFrom(devAddr, (uint8_t)min(length - k, I2CDEVLIB_WIRE_BUFFER_LENGTH)); - for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) { data[count] = Wire.read(); #ifdef I2CDEV_SERIAL_DEBUG @@ -288,8 +278,6 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 if (count + 1 < length) Serial.print(" "); #endif } - - Wire.endTransmission(); } #endif @@ -357,7 +345,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 Wire.beginTransmission(devAddr); Wire.send(regAddr); Wire.endTransmission(); - Wire.beginTransmission(devAddr); Wire.requestFrom(devAddr, (uint8_t)(length * 2)); // length=words, this wants bytes bool msb = true; // starts with MSB, then LSB @@ -376,8 +363,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 } msb = !msb; } - - Wire.endTransmission(); } #elif (ARDUINO == 100) // Arduino v1.0.0, Wire library @@ -390,7 +375,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 Wire.beginTransmission(devAddr); Wire.write(regAddr); Wire.endTransmission(); - Wire.beginTransmission(devAddr); Wire.requestFrom(devAddr, (uint8_t)(length * 2)); // length=words, this wants bytes bool msb = true; // starts with MSB, then LSB @@ -409,8 +393,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 } msb = !msb; } - - Wire.endTransmission(); } #elif (ARDUINO > 100) // Arduino v1.0.1+, Wire library @@ -423,7 +405,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 Wire.beginTransmission(devAddr); Wire.write(regAddr); Wire.endTransmission(); - Wire.beginTransmission(devAddr); Wire.requestFrom(devAddr, (uint8_t)(length * 2)); // length=words, this wants bytes bool msb = true; // starts with MSB, then LSB @@ -442,8 +423,6 @@ int8_t I2Cdev::readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint1 } msb = !msb; } - - Wire.endTransmission(); } #endif