Pages: [1]   Go Down
Author Topic: Possible Wire library doc error  (Read 347 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This web page:

  http://www.arduino.cc/en/Reference/Wire

states "There are both 7- and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it's being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8 bit address, you'll want to drop the low bit, yielding an address between 0 and 127."

I think that should read "...you'll want to drop the high bit, yielding an address between 0 and 127."

Wayne
« Last Edit: July 21, 2008, 08:48:17 pm by wholder » Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The low bit specifies whether you're reading or writing, so that's the bit you want to drop (i.e. shift the byte left by one bit).  But I realize the wording is somewhat confusing, so suggestions are welcome.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't used the library yet, so I can't say how the code was written.  But, as I was studying it with the intent to use it, this note seemed very confusing.  Since I2C is a serial protocol, it has no inherent byte alignment issues.  It's simply needs a 7 bit address.  So, the question I'm trying to answer is, how are these 7 bits aligned in the value passed to a function that takes an address (and, BTW, I assume that an address is a char, or byte value?  I'm nit sure, as the docs don't say.)

If the 7 bits are aligned to the LSB end of a char value, then you'd want to leave the MSB clear and you would end up with a value between 0-127 (inclusive.)  However, if the 7 bits are aligned to the MSB end and you are to leave the LSB clear, then you can't wind up with a value between 0-127.  You'll, instead, get all the even values between 0 and 256 (inclusive.)  So, no matter how you look at it, the description is confusing, IMO.

Wayne
Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 12
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed it to this:

There are both 7- and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it's being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8 bit address, you'll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127.

I hope it's clearer.   Yes, in a seven bit value, the high bit is clear, but in converting from the 8-bit value in a datasheet, you want to drop the low bit (which specifies whether you are reading or writing that address).
Logged

Pages: [1]   Go Up
Jump to: