Pages: [1]   Go Down
Author Topic: I2C - how does that work?  (Read 758 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Yes, we can (solder)!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't wrap my head around how I2C works with Arduino. I was checking examples and tutorials where two Arduinos are connected using I2C and analog 4 and 5 are connected, as well as ground, like here:

http://arduino.cc/en/Tutorial/MasterWriter

Reading multiple tutorials I don't doubt that it works yet it seems to defy logic to connect two analog inputs. How on Earth can anyone send bytes over two connected inputs??? How does the master send anything over an analog input? Thank you for your answers in advance!
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16518
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't wrap my head around how I2C works with Arduino. I was checking examples and tutorials where two Arduinos are connected using I2C and analog 4 and 5 are connected, as well as ground, like here:

http://arduino.cc/en/Tutorial/MasterWriter

Reading multiple tutorials I don't doubt that it works yet it seems to defy logic to connect two analog inputs.

Don't confuse the primary use of a given arduino pin to it's possible secondary uses. When the I2C hardware controller inside the  AVR 328p chip gets activated by the proper software commands, those analog input pins 4 and 5 are no longer analog input pins, but rather become the 2 I2C clock and data signals. Most arduino I/O pins have more then one purpose, such as pins 0 and 1 being hardware serial pins, if not being used as simple digital input or output pins. Even the analog input pins can be use as digital input or digital output pins if desired.

 How on Earth can anyone send bytes over two connected inputs??? How does the master send anything over an analog input? Thank you for your answers in advance!

Once those two pins are turned into I2C clock and data signals, they are no longer analog input pins. And the way I2C communications works, the single I2C data pin can be both an input pin to receive data or an output data to send data, it's said to be a bidirectional signal pin. You really don't have to understand it down to the gory details to utilize I2C modules with your arduino. It's main advantage is that it can be wired to up to 127 external I2C modules/devices/chips and sharing those same to I2C control signal pins, as each device has a unique I2C hardware address that allows the master I2C device (usually the arduino) to manage all those devices without conflicts.
Lefty

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Quote
... it seems to defy logic to connect two analog inputs ...

When I2C is activated it "takes over" those pins for the I2C functions.
Logged

London
Offline Offline
Full Member
***
Karma: 0
Posts: 192
Yes, we can (solder)!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much! Now it all makes sense. So much to learn...
Logged

Denmark
Offline Offline
God Member
*****
Karma: 8
Posts: 528
Please don't send questions as PM!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When in doubt, read the Data sheet!
http://www.atmel.com/Images/doc8271.pdf

// Per.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

On my quest to find the right way to write a code for I2C i found your post.

I'm a begginer and i just want to write a simple code just to read the data from a sensor which only uses I2C
so at the end i can get e.g.

Serial.println(sensordata);

I see that you guys have a complete comprehension on that topic that's why i post here instead of opening a new post that might have already been opened.

Thank you in advance.

With respect,

Minas
Logged

Pages: [1]   Go Up
Jump to: