Go Down

Topic: Beginner's queriesss on I2C Serial Connection (Read 12893 times) previous topic - next topic

fukkuen

hello everyone, i am a very beginner on arduino or electronics and i have a project in mind that require an arduino connecting 3 magnetometer(HMC 5843) at the same time. And that device use I2C as a protocol for serial communication.
All the thing i have done with arduino in the past is just to connect it with a single device. I never had a network of devices talked to my arduino.

My main question is: Can i connect 4 HMC5843 to one single arduino?
From this article (Introduction to I2C), It explains how several arduino communicate with each other by I2C. But can it applied to my situation where one arduino communicate with mutiple sensors?

Another stupid question: From the example on the internet I see the convention of using Analog pin4 is used as I2C SDA, and Analog pin5 is used as the serial clock. I just wonder why is the pin 4 and 5. Could i use 6 or 7 instead?  And more importantly, could i establish 2 I2C connection on the arduino? (i.e. using pin 4,5; 6,7 in pairs) I know the answer should be not but I don't know the explanation.

And i want to know the differences between RX/TX serial communication and the I2C. Actually i even don't know if they are the same thing or not. The RX/TX use the digital pin 0 and 1 while the I2C use analog 4 and 5...this is the only thing i know. So, under which circumstance I should use RX/TX and for the I2C?  Do the I2C connection use up the RX/TX port? (or could not do them at the same time)

I am really a beginner on electronics and so there is such questions(!)
I appreciate any help for me to start my first arduino project

ref:
HMC5843 on sparkfun: http://www.sparkfun.com/products/9371
Introduce to I2C: http://www.uchobby.com/index.php/2008/09/16/introduction-to-i2c/
Arduino I2C Expansion I/O: http://www.neufeld.newton.ks.us/electronics/?p=241

PaulS

Quote
Another stupid question: From the example on the internet I see the convention of using Analog pin4 is used as I2C SDA, and Analog pin5 is used as the serial clock. I just wonder why is the pin 4 and 5. Could i use 6 or 7 instead?  And more importantly, could i establish 2 I2C connection on the arduino? (i.e. using pin 4,5; 6,7 in pairs) I know the answer should be not but I don't know the explanation.

Using pins 4 and 5 is not just a convention. It is a necessity, as the I2C communication is controlled by hardware connected to those two pins.

No, you can not use pins 6 and 7, instead, for two reasons. First is that the I2C hardware is not connected to those pins. Second is that most Arduinos don't have analog pins 6 and 7.

Quote
And i want to know the differences between RX/TX serial communication and the I2C. Actually i even don't know if they are the same thing or not. The RX/TX use the digital pin 0 and 1 while the I2C use analog 4 and 5...this is the only thing i know. So, under which circumstance I should use RX/TX and for the I2C?  Do the I2C connection use up the RX/TX port? (or could not do them at the same time)

Complete different beasts. Whether to use serial communications or I2C communications depends on what you are trying to talk to. Obviously, whatever it is needs to be connected to the correct set of pins (digital 0 and 1 or analog 4 and 5). I2C and RX/TX are completely independent.

Quote
Can i connect 4 HMC5843 to one single arduino?

Can they be configured with different addresses? If so, yes. If not, no.
The art of getting good answers lies in asking good questions.

fukkuen

#2
Aug 06, 2011, 07:15 pm Last Edit: Aug 06, 2011, 07:17 pm by fukkuen Reason: 1
Quote

Can i connect 4 HMC5843 to one single arduino?

Quote

Can they be configured with different addresses? If so, yes. If not, no.

Quote
''The I2C hardware in the ATmega8/168/328 only supports one slave address.''

so i cant connect the arduino UNO to four slave devices?

from: ttp://arduino.cc/forum/index.php/topic,12296.0.html

PaulS

Why not post a link to the device you want to talk to? Perhaps there are other ways to talk to it, allowing you to talk to multiple instances.
The art of getting good answers lies in asking good questions.

retrolefty

Quote
so i cant connect the arduino UNO to four slave devices?


An Arduino Uno programmed to be a I2C 'master' can talk to up to 127 I2C slave devices (as long as every slave device has a unique address and only uses one address) on a single 2 wire I2C bus. That HMC5843 I2C slave device chip uses a I2C 7 bit address of 0x1E, so only one such device can operate with a single arduino board. You cannot attached mutiple I2C slaves that use the I2C address onto a single I2C bus.

Many I2C slave device chips have optional input pin(s) that can be wired to ground or Vcc to modify the address they respond to, therfore allowing muliple devices to operate on the bus, unfortunately the HMC5842 does not have that feature.

Lefty

fukkuen

thanks :)
but how can i know if the device address can be modified or not?
Will it be specified in the datasheet?
From the HMC5834 datasheet i can see that there is a column about 12c address...
<img src="http://farm7.static.flickr.com/6016/6016373441_aa401a1c6c.jpg" width="500" height="251" alt="Screen shot 2011-08-07 at 12.48.20 PM">
If there are mutiple addresses for an device, it will be specified in this column? Otherwise, from where i can acknowledge that mutiple address feature?

And what is meant by '0x' from 0x1E. The first two digi in heximal can already expresses more than 128 (7-bit), so what is the function of the 3rd and 4th digi?

CrossRoads

Typically the device datasheet will say clearly that it has some 'address' or 'select' pins (2 or 3) that you can externally connect High/Low as 0-0, 0-1, 1-0, 1-1, for example to allow four of that device. Those would then be recognized as part of the 7-bit address.

Talking to the part requires a couple of transfers - first is the address to tell the chip "listen up, I want to read (or write) a register", then "at this address", then master or slave will the data on the line using the next burst of clock activity.
Your screen shot is those registers.

0x means it is a Hex format number. Could be a byte, 0x00-0xFF, could be an integer, 0x0000-0xFFFF. could be a long/word/double (0x0000 0000 - 0xFFFF FFFF, spaces added for clarity).

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

Magnetometer reads X,Y,Z already, why would  you  need more than 1?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

fukkuen

Quote
Magnetometer reads X,Y,Z already, why would  you  need more than 1?

I need to measure the magnetic field at 3 points simultaneously when i move a magnet around the 3 points.

If all the compass is customized for robots, which need only one compass, then all the compass module should only have one unique address...
Have anybody seen a compass module with several address? If not, does it mean that i have to buy 3 arduino for each compass..? Or, alternatively, could i do it with 3 different compass module with diff address??

nickgammon


so i cant connect the arduino UNO to four slave devices?


The Arduino supports 119 slaves, addressed as 1 to 119. Address 0 is reserved for a "broadcast" and 120 to 127 are reserved for future use.

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

Quote
My main question is: Can i connect 4 HMC5843 to one single arduino?


The HMC5843, judging by the datasheet, has a hard-wired address. That is 0x1E (namely 30 in decimal). This will slow you down a bit if you want multiple devices. However there might be ways ...

It appears to draw under 1 mA of current on the supply rail, so one technique could be to connect multiple ones together (that is, have their SDA/SCL pins connected in parallel). Then connect the power pin to a digital pin (each) of the Arduino (eg. pins 3, 4, 5, 6). By raising one pin high you "power up" a particular device. Then use I2C to communicate with it, then power it down by dropping that pin back to low.

I used that technique to power up an I2C clock chip, to save power, so it was only on when I wanted it. From memory, waiting around 1 mS was all that was required for the device to become active, so that won't slow you down too much. In fact the datasheet says the "turn-on time" is 200 uS.

I don't know for sure if the devices will be annoyed if you have data on their SDA/SCL pins while they are not powered up, hopefully not. You might want to test with just a couple in case they self-destruct under those circumstances (unlikely I would think).


From the HMC5834 datasheet i can see that there is a column about 12c address...


Hopefully we are still talking about the HMC5843 and not the HMC5834, yes?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

CrossRoads

Interesting idea Nick.
Not sure how the active transmittter will like having 2 unpowered loads on the line.
I would suggest instead adding a demux chip so that only the selected device sees the clock line toggling. Requires 2 more arduino pins.
Use part like 74LS138.
With G1 high, G2B/ low, the selected output will mimic the state of G1A/.
http://focus.ti.com/lit/ds/symlink/sn74ls138.pdf
Should be fast too - just 13/14 nS of delay from G1A/ switching to the output switching.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

The part has an Off mode, attained by taking AVDD and DVDD both low.

AVDD has a 3.3V Max limit, DVDD has a 2V Max limit.

"Off Mode
During off mode device is off. No device functionality exists. Both AVDD and DVDD are low. The I2C bus is enabled for
use by other devices on the network in off mode. In this mode the I2C pins shall be in a high impedance state."

"Power Management
This device is capable of operating with a single supply (AVDD) or dual supplies (AVDD and DVDD). Pin VREN makes
this selection by enabling the internal digital supply voltage regulator. When VREN is tied to AVDD, the device is in single
supply operation; this device is powered from AVDD; and the internal voltage regulator is enabled."

So by connecting VREN to AVDD, and connecting DVDD as shown on page, one could theoretically use an (well, three) output pin, thru a resister and a 3.3V zener diode, to power the device. Use the pin as  Slave Selectt kind of feature - write it high, perhaps add in delayMicros(200), then read the device, then write it low.  I think the space taken up by the resistors and zeners would be better used by a  DIP tho.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nickgammon

Pretty much what I had in mind, Bob. Your extra detail was what was required to not blow the chip up ;).

Is the 74LS138 bidirectional? From what I can read it looks like it would only multiplex in one direction which wouldn't work with I2C (I am prepared to be corrected on this).

Quote
... so that only the selected device sees the clock line toggling ...


Well that might work of course. The devices see the data line changing but without the clock changing just ignore it.

Ah, isn't there going to be a potential problem with I2C? Unless the Uno is running on 3.3V logic (which it doesn't) then the I2C lines are going to be referencing 5V, but the HMC5843 is only powered with a maximum of 3.3V. The I2C lines (SDA/SCL)  - on that device - might not work at those voltage levels, in which case you might need an I2C repeater or buffer. Not sure, just wondering.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

CrossRoads

Be prepared to be corrected - the Clock only goes one direction!

The spec is not very informative on the I2C levels.  Only saying it has internals pullups to DCDD.

I could see a part  like this being handy here, and inexpensive too.

http://www.nkcelectronics.com/logic-level-converter.html
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nickgammon


Be prepared to be corrected - the Clock only goes one direction!


Yes, I agree, which is why I thought that just switching the clock would be OK.

I was about to link this part:

http://www.sparkfun.com/products/8745

But it looks identical to the one you linked, and yours is somewhat cheaper! The converter has two bidirectional ports and two unidirectional ones. You could use the bidirectional for SDA and the unidirectional for SCL. So you would only need two of them (for the four devices).* Although you still need to switch the AVDD/DVDD.

* Or do you? You might need only one, because you could connect all four devices to the "low" side of it.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Go Up