Author Topic: I2C confusion  (Read 2969 times)

0 Members and 1 Guest are viewing this topic.

Offline tyguy2Topic starter

  • Supporter
  • ****
  • Posts: 303
  • Country: us
I2C confusion
« on: May 20, 2016, 09:47:54 pm »
I've been trying to use an I2C on one of my projects, but whenever I look at a datasheet, there is always pin or 2 mentioned called the  "least significant bit of the device address." I don't know if I should just put it to ground, or what  :-// I feel like this is a newbie question, but I'm honestly stumped, and I feel stupid for not being able to find it online.

Example:
http://www.st.com/content/ccc/resource/technical/document/datasheet/bd/61/af/53/b5/f5/4d/7b/DM00037200.pdf/files/DM00037200.pdf/jcr:content/translations/en.DM00037200.pdf
Go to page 12
[Sarcastic comment] clever joke [/sarcastic comment]
Bitcoin:
12oV4dWZCAia7vXBzQzBF9wAt1U3JWZkpk
 

Offline hamdi.tn

  • Frequent Contributor
  • **
  • Posts: 623
  • Country: tn
Re: I2C confusion
« Reply #1 on: May 20, 2016, 10:02:13 pm »
this device have two adressable sub-device the accelerometer and the gyroscope, each one have this own adress and each adresse can be modified with SDO_A pin and SDO_G pin , the table you need are Table 16 and 17 on page 34.
 

Offline tyguy2Topic starter

  • Supporter
  • ****
  • Posts: 303
  • Country: us
Re: I2C confusion
« Reply #2 on: May 20, 2016, 10:04:13 pm »
So these pins would go to the microcontroller for control? Or would that be performed over the I2C bus?
[Sarcastic comment] clever joke [/sarcastic comment]
Bitcoin:
12oV4dWZCAia7vXBzQzBF9wAt1U3JWZkpk
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: I2C confusion
« Reply #3 on: May 20, 2016, 10:15:05 pm »
So these pins would go to the microcontroller for control?

If you want, or you could tie them high or low depending on what address you wanted to use.  Many I2C devices have configurable addresses so you can avoid address conflicts when hanging multiple devices off of a single bus. For example if you wanted to run two of these devices on a single bus, one of them would need those lines tied low and the other would need them tied high so their addresses wouldn't conflict.  If this is the only device you have on that I2C bus then it doesn't matter, pick either high or low and tie them there, then use the corresponding addresses.
 

Offline sca

  • Regular Contributor
  • *
  • Posts: 68
Re: I2C confusion
« Reply #4 on: May 20, 2016, 10:20:15 pm »
I2C devices have a slave address which is used to select them at the start of a transaction. The slave adress is generally fixed and shown in the data sheet.

In some cases, with smaller memories being one example, you need several identical devices connected to the same bus. You therefore need a way to discriminate between these devices. You therefore (typically) have the upper 4 bits of the slave addrss defined in the data sheet and hard coded, with the lower 3 bits spefified by the A2..0 pins.

If you have only one device you can tie the address pins to logic 0 or 1 or any convenient combination, and just derive the appropriate complete slave address.


sca
 

Offline hamdi.tn

  • Frequent Contributor
  • **
  • Posts: 623
  • Country: tn
Re: I2C confusion
« Reply #5 on: May 20, 2016, 10:24:30 pm »
i don't think that you need to control those pins with the uC, just tie them to VCC or  GND.
 

Offline tyguy2Topic starter

  • Supporter
  • ****
  • Posts: 303
  • Country: us
Re: I2C confusion
« Reply #6 on: May 20, 2016, 10:29:23 pm »
I'm going to end up having about 5 devices on this line, so g=how would I differentiate between them? I'm fairly sure most of them have different addresses (ie 00010100), so if I tie one to ground and the other to VCC, would that affect anything?
[Sarcastic comment] clever joke [/sarcastic comment]
Bitcoin:
12oV4dWZCAia7vXBzQzBF9wAt1U3JWZkpk
 

Offline tyguy2Topic starter

  • Supporter
  • ****
  • Posts: 303
  • Country: us
Re: I2C confusion
« Reply #7 on: May 20, 2016, 10:32:22 pm »
Also, some of the datasheets only provide 4 bit addresses (http://ww1.microchip.com/downloads/en/DeviceDoc/22003e.pdf page 35), with no address pins. How would I distinguish between the 8 bit addresses and the 4 bit ones?
[Sarcastic comment] clever joke [/sarcastic comment]
Bitcoin:
12oV4dWZCAia7vXBzQzBF9wAt1U3JWZkpk
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12912
Re: I2C confusion
« Reply #8 on: May 20, 2016, 11:10:49 pm »
Some I2C chips only read their address select pins at powerup.  If that's the case connecting those pins to a MCU is useless.  Others read them at every Start bit so instead of hard-wiring them as normal, you can drive one or more of the address select pins from your MCU to multiplex more devices of the same type than can normally be addressed without conflict onto the bus under the control of the master MCU as an address conflict only matters if the master attempts to access that device.

The Microchip MCP3421 ADC has a factory configured address: 1101xxx.  xxx varies from 000 to 011 depending on the exact part number you order.

You need to avoid address conflicts - see https://learn.sparkfun.com/tutorials/i2c for an introduction to I2C including 7 bit and 10 bit addressing.
« Last Edit: May 20, 2016, 11:26:16 pm by Ian.M »
 

Offline tyguy2Topic starter

  • Supporter
  • ****
  • Posts: 303
  • Country: us
Re: I2C confusion
« Reply #9 on: May 20, 2016, 11:14:27 pm »
I understand the address conflicts issue. I think I understand now. In the first case (least significant bit of the device address.) would be used to determine the address. In the second case, the part has a hard coded address that varies from part number to part number. Thanks for clearing up the confusion!
[Sarcastic comment] clever joke [/sarcastic comment]
Bitcoin:
12oV4dWZCAia7vXBzQzBF9wAt1U3JWZkpk
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: I2C confusion
« Reply #10 on: May 20, 2016, 11:58:39 pm »
Since you have several devices, you should just make a table of their addresses, so you can easily identify where there are/might be conflicts and either set the address line appropriately or pick a specific part number with a free address.
 

Offline hamdi.tn

  • Frequent Contributor
  • **
  • Posts: 623
  • Country: tn
Re: I2C confusion
« Reply #11 on: May 21, 2016, 12:26:51 am »
you use some of the host microcontroller hardware flexibilty to avoid conflict too .. like not using the I2C bus for all slaves or use the same I2C hardware but change alternate functions on some other pins ...
 

Offline Wilksey

  • Super Contributor
  • ***
  • Posts: 1329
Re: I2C confusion
« Reply #12 on: May 21, 2016, 12:46:57 am »
You usually have a base address, say 50, then you get a few lines of address which is essentially a binary representation.
So, address 1 high, address 2 low, the address will be 51, address 1 low, address 2 high, address will be 52, both address lines low, address will be 50, both high, address will be 53 etc etc.
 

Offline Raj

  • Frequent Contributor
  • **
  • Posts: 694
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: I2C confusion
« Reply #13 on: May 22, 2016, 02:58:33 pm »
page 32 and onwards of datasheet has the explanation...get a printout of page 12,32,33,34
it will make it easy...meanwhile i'll have a look at it and try to make sense out of it.
« Last Edit: May 22, 2016, 03:02:31 pm by Raj »
 

Offline Cerebus

  • Super Contributor
  • ***
  • Posts: 10576
  • Country: gb
Re: I2C confusion
« Reply #14 on: May 22, 2016, 03:10:10 pm »
The Microchip MCP3421 ADC has a factory configured address: 1101xxx.  xxx varies from 000 to 011 depending on the exact part number you order.

Oh, that could bite you on the bum! I bet, somewhere, there's a stack of reels of those where someone has ordered 10 reels of one part where they should have ordered 21/2 reels of each of the possible sub-parts. I further bet that the information you need to avoid doing this is in small print on the 2nd to last page of the datasheet. Just checked - 4th to last page.

Anybody got a syringe I can use to squeeze the magic smoke back into this?
 
The following users thanked this post: Ian.M

Offline Raj

  • Frequent Contributor
  • **
  • Posts: 694
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: I2C confusion
« Reply #15 on: May 22, 2016, 03:16:53 pm »
For having multiple devices, you'll have to wire each one differently
apprently,
if sdo pins are made high, they will change the slave address
eg

if all pins low, slave address is                                     00110001  for read operation on lenier accelerator ,         00110000 for write operation
 
if pin sdo_a is high, slave address is                           00110011 for read operation on lenier accelerator ,         00110010 for write operation
 
if all pins low, slave address is                                     11010101   for read operation on angular rate sense ,         11010100  for write operation

if pin sdo_g is high, slave address is                           11010111  for read operation angular rate sense , and   11010110   for write operation

sdo_a pin wil not change slave address for angular rate thing
sdo_g pin will not change address for lenier accelerator
« Last Edit: May 22, 2016, 03:23:24 pm by Raj »
 

Offline Raj

  • Frequent Contributor
  • **
  • Posts: 694
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: I2C confusion
« Reply #16 on: May 22, 2016, 03:25:05 pm »
for using more than 2 chips, I recommend using sdo pins like as if they were chip select pins
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf