lkml.org 
[lkml]   [2013]   [Jul]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: What endianness is word in i2c_smbus_data?
Andy Lutomirski wrote:
> I'm rather confused here. In SMBUS, the "read word" operation returns
> two bytes. Just to be confusing, the SMBUS spec calls the first byte
> "Data Byte Low" and the second byte "Data Byte High". But they really
> are the first and second bytes -- Read Word will return whatever Read
> Byte would have as its first byte. Let's call these bytes B1 and B2
> for first and second.

No that tells you WHATEVER the HOST endianness the bus transfer is
always treated the same, so when two bytes are combined (into a word,
the first will be the low byte for the HOST and the second will be the
high byte for the HOST. These may actually be different for the SLAVE
device.

> The eeprom and at24 drivers expect data->word to be (B2 << 8) | B1.
> That is, data->word is the cpu representation of the value on the bus
> if that value is treated as little-endian. Is that indeed the correct
> interpretation? If so, should it be documented somewhere?

Several I2C devices eg PCF8575 and MCP23017 often give 16 bit results as
2 byte transfers, knowing which byte order from device to bus to host
needs matching.

So knowing that a word is made up of bytes transmitted or received in a
particular order is important as some devices do transmit high byte
first.

> --Andy
>


--
Paul Carpenter | paul@pcserviceselectronics.co.uk
<http://www.pcserviceselectronics.co.uk/> PC Services
<http://www.pcserviceselectronics.co.uk/pi/> Raspberry Pi Add-ons
<http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font
<http://www.gnuh8.org.uk/> GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
<http://www.badweb.org.uk/> For those web sites you hate


\
 
 \ /
  Last update: 2013-07-17 17:01    [W:0.342 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site