Wire library on a device address >  than 127

So, I am having trouble using the I2C interface to connect to a ualfat OEM board. I want to use I2C as I've successfully used it for another device and would be glad to piggy back on the Wire library.

Anyhow, I am getting such strange results. The ack comes back fine but the data read is always 0. If I unplug the data cable the ack never happens so I assume some communication is happening.

Anyhow, I noticed that the wire library says it can connect to any device with int value up to 127. This device's address is 0xA4, which is 164.

Is this a limitation of the Wire library? Is there any way around this?

I tried rerunning the code with the address set to 5, for kicks - and got the same results. This makes me suspect something is up with my wiring.

Thanks! Lucas

Hi,

Search the forums (with Google) for threads discussing this issue--I believe it's to do with the top bit being set for read/write.

--Phil.

Check out this thread http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1168573932/12#12 Simply what you ahve to do is to remove the LSB... for instance if the datasheet say that the device have address write 0xA2(B10100010) and read 0xA3(B10100011) then you simply use B1010001 in both cases... and the wire librarý will take care of the rest....

/J

great! thanks

Read those posts, they only briefly discuss dropping the LSB and using wire. Wire will take care of the read / write bit.

Ok but still, If my previous address was B10100100, how is wire going to differentiate my address with the LSB dropped and an address of this value?

ie how does it know that my B1010010 does not equal B01010010

it just makes zero sense to me? There's gotta be some way to signal to the Wire library that it's getting a truncated address. I've successfully used the wire library on address 104, so it's not like it just ignores a bit by default?

Thanks for the help Lucas

Ok, forgot to awnser your question, the two binary numbers you compare is infact the same number so, no, wire can’t differ from the two of them since it’s the same :stuck_out_tongue:
however if your initial(whit lsb) address B10100100 and another one is B01010010 they will become B1010010 and B0101001… Ok, now i get the feeling that i’m loosing track here… please tell me if you have further questions…

/J

Oh I get it! so the 127 is no just a Wire thing, it's actually a standard I2C concept.

Now I get it, thanks! Lucas

I2C addresses consist of only 7 bits. The last bit is Read/Write - Write when 0, read when 1. So, if you have a data sheet that says the address of a device is 0xA4, likely that’s the Write address. The Wire library is poorly documented on this, but you have to pass the device address, which is the top 7 bits. So your A4 will become 0x52 and the Wire library will figure out whether you want the read or the write address.

So, to answer your question, the 7 bit address B1010010 will be made into B10100100 for writes to the device and B10100101 for reads from it, while the 8-bit address I couldn’t say what would happen… probably that it will get made into an incorrect 9-bit address. Wire’s functions expect the 7-bit device address - without the Read/Write bit.

I had a lot of problems with I2C until I figured this out. I was trying to read input from an I/O expander, and the data that was getting read back to me was exactly what I had ‘written’ to the device moments before, but the voltage of the output pins reflected otherwise. So, although it may appear to be working properly, the device hasn’t actually received any data. It really frustrated me, because this little ‘quirk’ is documented nowhere on the Arduino or Wiring site. I had to read about it on a blog somewhere on the internet.

I had a lot of problems with I2C until I figured this out. I was trying to read input from an I/O expander, and the data that was getting read back to me was exactly what I had 'written' to the device moments before, but the voltage of the output pins reflected otherwise. So, although it may appear to be working properly, the device hasn't actually received any data. It really frustrated me, because this little 'quirk' is documented nowhere on the Arduino or Wiring site. I had to read about it on a blog somewhere on the internet.

Interesting, that's EXACTLY my problem. I write a 'V' to ask the version and I get back 'V'

thanks!

I'd assume it's some sort of buffer thing... Wire sticking the data you're writing out into the buffer, sends it along the wire, and then waits for a read. When it doesn't receive any data, it passes back whatever is in the buffer... which happens to be exactly what you wrote in. ... I could be wrong though, but this would sort of make sense as to why we get data out instead of a failure (which would be preferable in this case.)

Anyway. Good luck with your project! (:

I believe it's to do with the top bit being set for read/write.

As you'll learn from reading the thread linked above, I actually got this backwards--it's the lowest (bottom) bit that is used for read/write.

--Phil.

binary trick.. :) Wire library treat I2C slave address only 7 bit. last Read/Write bit assert by library call. most of IC/Module datasheet show 8 bit include R/W bit you may define codelike this

define ualfatID 0x52

or

define ualfatID (0xA4>>1)

that's right to work with Wire lib.