Questions about I2C on Arduino

Hi, guys

I am currently learning how to program I2C on Arduino. I have read my tutorials, and I tried some of them. However, I am still very confused.

  1. Use Wire.read() to save the received information in a variable. Should I declare the variable as a bit, or an int?

  2. Many tutorials set those variables as pointers (ex. *a, *b). Is this necessary?

  3. By looking at data sheet, each address have 8 bits. Will all 8 bits be passed at the same time (Have one Wire.read()), or will each bit would be passed individually ( Have more than one Wire.read())

  4. For programming I2C, we need a address for the devices...where can I find that address on the data sheet?

  5. I wrote a program for Real Time Clock, and I keep getting -1s or 255s...Can someone explain this a little bit?

If you have read all the questions already, I really appreciate your time and patience. If you guys would like to help me out with this problems, that would be great!

Sincerely

  1. Byte is optimal. Haveyou read this guide? http://tronixstuff.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/

Sorry for the late replay.

Yes, I have read the guide, both part one and part two.

If you have more suggestions for guides, please let me know, and I will be glad to read them.

Sincerely

  1. In general you don't have to use pointers but if an I2C (or any other) library requires that you pass it a pointer then that's what you have to give it.

  2. The I2C protocol involves passing 8 bits at a time.

  3. If the datasheet has a section on the I2C protocol then that's the best place to look for the address. Otherwise, you just have to read the whole datasheet until you find the address.

  4. If all you get is -1 or 255 it means that the RTC isn't wired up properly and the Arduino is not seeing any changes on the SDA line so it reads it as all ones (in binary 255 is 11111111). It is possible that it can read it as all zero, but it is much more likely to see the line is HIGH which will read as a one.

Pete

See http://www.gammon.com.au/i2c

we need a address for the devices...where can I find that address on the data sheet?

What device? What datasheet? (link).

  1. I wrote a program for Real Time Clock, and I keep getting -1s or 255s...Can someone explain this a little bit?

You post your code and then we'll explain.