Go Down

Topic: Possible Wire library doc error (Read 358 times) previous topic - next topic

wholder

Jul 22, 2008, 03:47 am Last Edit: Jul 22, 2008, 03:48 am by wholder Reason: 1
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

mellis

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.

wholder

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

mellis

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).

Go Up