Beginner's queriesss on I2C Serial Connection

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: Triple Axis Magnetometer Breakout - HMC5843 - SEN-09371 - SparkFun Electronics
Introduce to I2C: Introduction to I2C – uCHobby
Arduino I2C Expansion I/O: http://www.neufeld.newton.ks.us/electronics/?p=241

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.

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.

Can i connect 4 HMC5843 to one single arduino?

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

Can i connect 4 HMC5843 to one single arduino?

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

''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

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.

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

thanks :slight_smile:
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...

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?

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).

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

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??

fukkuen:
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.

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).

fukkuen:
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?

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/.

Should be fast too - just 13/14 nS of delay from G1A/ switching to the output switching.

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.

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).

... 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.

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

CrossRoads:
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:

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.

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

http://www.nkcelectronics.com/logic-level-converter.html

Sigh. Only $1 each. I was about to order 20 of them for future use, until I saw the $60 shipping bill.

$60! Whooaaa!

Check back with them - USPS has $14 flat rate postage to any country (Canada/Mexico less). See If they'll ship that way.

That was for USPS.

http://ircalc.usps.gov/?country=10013

If you click on "Priority Mail International Large Flat Rate Box" it quotes "Post Office Price $58.50".

But if I go back and choose "Priority Mail® International Small Flat Rate Box" it quotes $13.95, which is more reasonable.

I'll try to negotiate with NKC Electronics. They don't offer the smaller package on their automated system.

Yeah, press them on it.
I asked UPS about a shipment to Belgium - they wanted $83!
$14 a lot more reasonable.

This should solve your problem.... DssCircuits.com is for sale | HugeDomains

It multiplexes the I2C signal and takes care of the logic level conversion at the same time.