I2C confusion - Page 1
Forum section: electronics / beginners

author: tyguy2
author_rank: Unknown
timestamp: May 20, 2016, 09:47:54 pm
content: 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 whatI 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.pdfGo to page 12

author: hamdi.tn
author_rank: Frequent Contributor
timestamp: May 20, 2016, 10:02:13 pm
content: 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.

author: tyguy2
author_rank: Unknown
timestamp: May 20, 2016, 10:04:13 pm
content: So these pins would go to the microcontroller for control? Or would that be performed over the I2C bus?

author: suicidaleggroll
author_rank: Super Contributor
timestamp: May 20, 2016, 10:15:05 pm
content: Quote from: tyguy2 on May 20, 2016, 10:04:13 pmIf 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.

author: sca
author_rank: Regular Contributor
timestamp: May 20, 2016, 10:20:15 pm
content: 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

author: hamdi.tn
author_rank: Frequent Contributor
timestamp: May 20, 2016, 10:24:30 pm
content: i don't think that you need to control those pins with the uC, just tie them to VCC or GND.

author: tyguy2
author_rank: Unknown
timestamp: May 20, 2016, 10:29:23 pm
content: 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?

author: tyguy2
author_rank: Unknown
timestamp: May 20, 2016, 10:32:22 pm
content: Also, some of the datasheets only provide 4 bit addresses (http://ww1.microchip.com/downloads/en/DeviceDoc/22003e.pdfpage 35), with no address pins. How would I distinguish between the 8 bit addresses and the 4 bit ones?

author: Ian.M
author_rank: Super Contributor
timestamp: May 20, 2016, 11:10:49 pm
content: 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 - seehttps://learn.sparkfun.com/tutorials/i2cfor an introduction to I2C including 7 bit and 10 bit addressing.

author: tyguy2
author_rank: Unknown
timestamp: May 20, 2016, 11:14:27 pm
content: 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!

author: suicidaleggroll
author_rank: Super Contributor
timestamp: May 20, 2016, 11:58:39 pm
content: 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.

author: hamdi.tn
author_rank: Frequent Contributor
timestamp: May 21, 2016, 12:26:51 am
content: 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 ...

author: Wilksey
author_rank: Super Contributor
timestamp: May 21, 2016, 12:46:57 am
content: 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.

author: Raj
author_rank: Frequent Contributor
timestamp: May 22, 2016, 02:58:33 pm
content: page 32 and onwards of datasheet has the explanation...get a printout of page 12,32,33,34it will make it easy...meanwhile i'll have a look at it and try to make sense out of it.

author: Cerebus
author_rank: Super Contributor
timestamp: May 22, 2016, 03:10:10 pm
content: Quote from: Ian.M on May 20, 2016, 11:10:49 pmOh, 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/2reels 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.

author: Raj
author_rank: Frequent Contributor
timestamp: May 22, 2016, 03:16:53 pm
content: For having multiple devices, you'll have to wire each one differentlyapprently,if sdo pins are made high, they will change the slave addressegif all pins low, slave address is 00110001 for read operation onlenier accelerator, 00110000 for write operationif pin sdo_a is high, slave address is 00110011 for read operation onlenier accelerator, 00110010 for write operationif all pins low, slave address is 11010101 for read operation onangular rate sense, 11010100 for write operationif pin sdo_g is high, slave address is 11010111 for read operationangular rate sense, and 11010110 for write operationsdo_a pin wil not change slave address for angular rate thingsdo_g pin will not change address for lenier accelerator

author: Raj
author_rank: Frequent Contributor
timestamp: May 22, 2016, 03:25:05 pm
content: for using more than 2 chips, I recommend using sdo pins like as if they were chip select pins