3

The WiringPi library has APIs called wiringPiI2CWriteReg16 and wiringPiI2CReadReg16 for writing and reading 16 bits of data from a given I2C device at a specific register. Since the resulting 16 bit value is made up from the read of two 8 bit bytes, is the value Low Byte / High Byte or High Byte / Low Byte?

1

By writing an application that reads two 8 bit values at adjacent I2C registers and comparing these against the value returned from a wiringPiI2CReadReg16 I conclude through experimentation that the order of the data returned is Low Byte / High Byte.

0

The byte endianess is determined by the I2C device.

It may be low endian or high endian as defined by the I2C device's datasheet.

  • Imagine that an I2C device gave the byte value X and address n and Y at address n+1. Using the WiringPI API, we have a 16 bit read API that doesn't document how it interprets the data. The data could be read as X<< 8 | Y or Y<<8 | X. This does not appear related to the intended value of any I2C device ... but rather, what is coded within WiringPI's 16 bit read function? – Kolban Dec 14 '15 at 15:30
  • Yes, to make sense of I2C words you need to know at least two things 1) the byte order as used by the device, 2) the byte order as presented to you by the client function you are using. – joan Dec 14 '15 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.