Skip to content

Commit

Permalink
Do not call Wire.requestFrom() if rx=0
Browse files Browse the repository at this point in the history
  • Loading branch information
hanyazou committed Jun 10, 2017
1 parent 2735de6 commit b2407aa
Show file tree
Hide file tree
Showing 2 changed files with 439 additions and 8 deletions.
18 changes: 10 additions & 8 deletions BMI160Gen.cpp
Expand Up @@ -110,17 +110,19 @@ int BMI160GenClass::i2c_xfer(uint8_t *buf, unsigned tx_cnt, unsigned rx_cnt)
if( Wire.endTransmission() != 0 ) {
Serial.println("Wire.endTransmission() failed.");
}
Wire.requestFrom(i2c_addr, rx_cnt);
p = buf;
while ( Wire.available() && 0 < rx_cnt) {
rx_cnt--;
if (0 < rx_cnt) {
Wire.requestFrom(i2c_addr, rx_cnt);
p = buf;
while ( Wire.available() && 0 < rx_cnt) {
rx_cnt--;
#ifdef DEBUG
int t = *p++ = Wire.read();
Serial.print(" ");
Serial.print(t, HEX);
int t = *p++ = Wire.read();
Serial.print(" ");
Serial.print(t, HEX);
#else
*p++ = Wire.read();;
*p++ = Wire.read();;
#endif // DEBUG
}
}

#ifdef DEBUG
Expand Down

0 comments on commit b2407aa

Please sign in to comment.