Skip to content

Commit 0451a44

Browse files
committed
Removes Wire.endTransmission from functions that are reading from the IC
* using requestFrom and endTransmission together is incorrect usage of the requestFrom function * rolls version
1 parent fe539fd commit 0451a44

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun KX13X Arduino Library
2-
version=1.0.2
2+
version=1.0.3
33
author=SparkFun Electronics <[email protected]>
44
maintainer=Elias Santistevan @ SparkFun Electronics
55
sentence=Communicates and configures the SparkFun KX132/KX134 Accelerometer.

src/SparkFun_Qwiic_KX13X.cpp

+13-18
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,12 @@ KX13X_STATUS_t QwiicKX13xCore::readRegister(uint8_t *dataPointer, uint8_t reg)
434434
i2cResult = _i2cPort->endTransmission(false);
435435
if( i2cResult != 0 )
436436
return KX13X_I2C_ERROR; //Error: Sensor did not ack
437-
_i2cPort->requestFrom(static_cast<uint8_t>(_deviceAddress), static_cast<uint8_t>(1));
438-
*dataPointer = _i2cPort->read();
439-
i2cResult = _i2cPort->endTransmission();
440-
if( i2cResult != 0 )
441-
return KX13X_I2C_ERROR; //Error: Sensor did not ack
442-
return KX13X_SUCCESS;
437+
i2cResult = _i2cPort->requestFrom(static_cast<uint8_t>(_deviceAddress), static_cast<uint8_t>(1)); //returns number of bytes
438+
if( i2cResult != 0) {
439+
*dataPointer = _i2cPort->read();
440+
return KX13X_SUCCESS;
441+
}
442+
return KX13X_I2C_ERROR; //Error: Sensor did not ack
443443
}
444444
}
445445

@@ -474,14 +474,12 @@ KX13X_STATUS_t QwiicKX13xCore::readMultipleRegisters(uint8_t reg, uint8_t dataBu
474474
if( i2cResult != 0 )
475475
return KX13X_I2C_ERROR; //Error: Sensor did not ack
476476

477-
_i2cPort->requestFrom(static_cast<uint8_t>(_deviceAddress), numBytes, false);
477+
i2cResult = _i2cPort->requestFrom(static_cast<uint8_t>(_deviceAddress), numBytes, false);
478+
if( i2cResult == 0 )
479+
return KX13X_I2C_ERROR;
478480
for(size_t i = 0; i < numBytes; i++) {
479481
dataBuffer[i] = _i2cPort->read();
480482
}
481-
482-
i2cResult = _i2cPort->endTransmission();
483-
if( i2cResult != 0 )
484-
return KX13X_I2C_ERROR; //Error: Sensor did not ack
485483
return KX13X_SUCCESS;
486484
}
487485
}
@@ -507,19 +505,16 @@ KX13X_STATUS_t QwiicKX13xCore::overBufLenI2CRead(uint8_t reg, uint8_t dataBuffer
507505
else
508506
resizedRead = numBytes;
509507

510-
_i2cPort->requestFrom(static_cast<uint8_t>(_deviceAddress), resizedRead, false); //false = repeated start
508+
i2cResult = _i2cPort->requestFrom(static_cast<uint8_t>(_deviceAddress), resizedRead, false); //false = repeated start
509+
if( i2cResult == 0 )
510+
return KX13X_I2C_ERROR;
511511
for(size_t i = 0; i < resizedRead; i++) {
512512
dataBuffer[arrayPlaceHolder] = _i2cPort->read();
513513
arrayPlaceHolder++;
514514
}
515515
numBytes = numBytes - MAX_BUFFER_LENGTH; // end condition
516516
}
517-
518-
i2cResult = _i2cPort->endTransmission();
519-
if( i2cResult != 0 )
520-
return KX13X_I2C_ERROR; //Error: Sensor did not ack
521-
else
522-
return KX13X_SUCCESS;
517+
return KX13X_SUCCESS;
523518
}
524519

525520
// Writes the given value to the given register, using the provided mask and

0 commit comments

Comments
 (0)