Wiring Forum
Wiring Hardware >> Troubleshooting >> I2C .... bits?

Message started by Kars on 10/19/08 at 15:06:48

Title: I2C .... bits?
Post by Kars on 10/19/08 at 15:06:48
Hi all,

After playing with some I2C deviceas, and not knowing why it didn't work, I started searching.
The beginTransmission() explaination page(http://www.wiring.org.co/learning/libraries/Wire/Wire_beginTransmission_.html)  says:

address =An int value between 0 and 127 specifying the address of the device to trasmit to (BTW, there's a typo there, it should be transmit  ;) )

BUT! My device uses the adress: 0xC0 which is 192. So therefor it is not working!
Could the I2C be 8 bits instead of 7 bits?

Or is there an other option?(we can only change the adress to C2/C4/C6, not lower)



Title: Re: I2C .... bits?
Post by barragan on 10/19/08 at 17:36:23
hey Kars, thanks, yes the Wire library uses a 0-127 address, please check this example: http://wiring.org.co/learning/examples/HMC6352sparkfun.html
In there you´ll find the device address is shifted :

int compassAddress = 0x42 >> 1;  // From datasheet compass address is 0x42
                                // shift the address 1 bit right, the Wire library only needs the 7
                                // most significant bits for the address

Title: Re: I2C .... bits?
Post by Titus on 10/21/08 at 07:14:23
So just setting it to 0x60 would work too?


Title: Re: I2C .... bits?
Post by barragan on 10/22/08 at 02:52:10
just do it this way:
int address = 0xC0 >> 1;

that´s all, now address contains the right address to use.



Title: Re: I2C .... bits?
Post by Titus on 10/22/08 at 13:40:31
Hi all,

We got a strange thing going on:
We ask a sensor over I2C to return something.
BUT even when nothing is connected to the I2C pins, we get the same value as sent.

here's our code:

# define SENSORADDRESS 0x27
# define RESULTREGISTER 0x24

#include <TwoWire.h>

void setup()

void loop()
 Serial.print(" ");

int Cball()

 Wire.requestFrom(SENSORADDRESS, 1);
  while (Wire.available() < 1 )   {
   // wait for result
 return Wire.receive();

So the RESULTREGISTER is the value returned, no matter what SENSORADRESS we take, or what RESULTREGISTER, or connect I2C devices.

Please help!!

Titus(and Kars)

Title: Re: I2C .... bits?
Post by barragan on 10/23/08 at 05:04:02
hey guys, could you post a datasheet or part number for the device you´re using?

Title: Re: I2C .... bits?
Post by Titus on 10/23/08 at 09:09:58
Here it is:

But even when that thing is not connected, wiring returns the same value as was sent. I will try to hook up the compass later this day, to see if that still works, otherwise it's wiring 17

I'll try wiring 16 btw.


Title: Re: I2C .... bits?
Post by Titus on 10/30/08 at 07:22:47
Well, I did try my CMPS03 Compass sensor today, didn't work as suspected. Strange.
I'll ask kars to test his compass with wiring 0017.
any idea?

Title: Re: I2C .... bits?
Post by Titus on 12/30/08 at 17:38:01
Got it working today!!!!!!
Actually a very stupid mistake:
we had << in stead of >>


Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.