Skip to content

Commit b40c9bb

Browse files
committed
Fix I2C issue
1 parent 8a97102 commit b40c9bb

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/wireUtils.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static inline uint8_t writeRegister16Bits(TwoWire *wire, uint8_t address, uint8_
6060

6161
/**
6262
* @brief Reads a 16-bit register from a specified address using the given I2C wire object.
63+
* The data order is LSB(yte) first.
6364
*
6465
* @param wire The I2C wire object to use for communication.
6566
* @param address The address of the device to read from.
@@ -70,13 +71,11 @@ static inline uint16_t readRegister16Bits(TwoWire *wire, uint8_t address, uint8_
7071
{
7172
wire->beginTransmission(address);
7273
wire->write(reg);
73-
wire->endTransmission();
74-
wire->requestFrom(address, 2);
75-
uint16_t registerValue = (uint16_t)wire->read();
76-
registerValue |= (uint16_t)wire->read() << 8;
77-
wire->endTransmission();
74+
wire->endTransmission(false);
75+
wire->requestFrom(address, 2, true);
76+
uint16_t registerValue = (uint16_t)wire->read(); // Read LSB
77+
registerValue |= (uint16_t)wire->read() << 8; // Read MSB
7878
return registerValue;
79-
8079
}
8180

8281
/**

0 commit comments

Comments
 (0)