/* WRITE REGISTER
Wire data to a TMP117 register
*/
void TMP117::writeRegister(uint8_t reg, uint16_t data) // originally TMP117_Register reg
{
_i2cPort->beginTransmission(_deviceAddress); // Originally cast uint8_t when a register value again
_i2cPort->write(reg);
_i2cPort->write(highByte(data)); // Write MSB (D15-D8)
_i2cPort->write(lowByte(data)); // Write LSB (D7-D0)
_i2cPort->endTransmission(); // Stop transmitting data
}
/* READ REGISTER
This function reads the register bytes from the sensor when called upon.
This reads 2 bytes of information from the 16-bit registers.
*/
uint16_t TMP117::readRegister(uint8_t reg) // originally TMP117_Register reg
{
_i2cPort->beginTransmission(_deviceAddress); // Originally cast (uint8_t)
_i2cPort->write(reg);
_i2cPort->endTransmission(); // endTransmission but keep the connection active
_i2cPort->requestFrom(_deviceAddress, (uint8_t)2); // Ask for 2 bytes, once done, bus is released by default
uint8_t data[2] = {0}; // Declares an array of length 2 to be empty
int16_t datac = 0; // Declares the return variable to be 0
if (_i2cPort->available() <= 2) // Won't read more than 2 bits
{
data[0] = _i2cPort->read(); // Reads the first set of bits (D15-D8)
data[1] = _i2cPort->read(); // Reads the second set of bits (D7-D0)
datac = ((data[0] << 8) | data[1]); // Swap the LSB and the MSB
}
return datac;
}
The same source as above ...
Analyze the difference ... and give it also a try ...