r/AskElectronics 3d ago

How are unique I2C addresses handled in mass production

Hi!

I am developing a product that will be utilising I2C protocol for communication with various things like LCD, BMS and more. I just realized that these component have unique address ids and im wondering how that is handled in mass production units when you obviously dont want to update the source code for each device to match the unique ID of the component.

3 Upvotes

17 comments sorted by

u/AutoModerator 3d ago

Do you have a question involving batteries or cells?

If it's about designing, repairing or modifying an electronic circuit to which batteries are connected, you're in the right place. Everything else should go in /r/batteries:

/r/batteries is for questions about: batteries, cells, UPSs, chargers and management systems; use, type, buying, capacity, setup, parallel/serial configurations etc.

Questions about connecting pre-built modules and batteries to solar panels goes in /r/batteries or /r/solar. Please also check our wiki page on cells and batteries: https://www.reddit.com/r/AskElectronics/wiki/batteries

If you decide to move your post elsewhere, or the wiki answers your question, please delete the one here. Thanks!

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

22

u/triffid_hunter Director of EE@HAX 3d ago

They're not unique - there's only 126 available addresses, and the address for each device is listed in its datasheet.

13

u/markus_b 3d ago

I think you misunderstand this. The Bus address for the same device is always the same. The LCD has always address 0x16, the BMS 0x45, etc. Some devices may have a unique serial number, but it is not used for addressing.

1

u/juaspo 1d ago

Ok thanks for the clarification! I get it now.

7

u/agent_kater 3d ago

I think you're mixing something up here. I2C usually doesn't have unique addresses.

So when you use more than one device that has the same address, you put them behind something like a TCA9548A.

Dallas 1-wire protocol has unique addresses. The way this works is that during startup the master runs a binary search through the address space, asking "is there anyone on the bus with an address above X", if more than one device answers, it splits the range in two and asks again, until it has identified all the devices on the bus.

6

u/JimHeaney 3d ago

Yep, the terms you're conflating OP are "bus unique" (only one device with address 0x10 allowed on the bus) for i2c and similar, and "globally unique" (only one device with address 0x10 in the entire world) for OneWire, MAC, etc.

Every device with bus unique components has the same addresses and therefore the same code. In a globally unique device you need to ID them some other way, or treat the ID as a variable (e.g. you determine "the MAC" and use "the MAC" here, rather than finding the MAC is 10:32:24:09, then updating your code to use 10:32:24:09).

1

u/juaspo 1d ago

Ok thanks for the clarification. I have worked with both a while back so I might have confused things together

-1

u/jacky4566 3d ago

*or use an IC with configurable address. Or use SPI because it's better :P

4

u/JimHeaney 3d ago

SPI isn't better in most applications. The higher bandwidth isn't used by most devices, and you quickly increase routing complexity with all the GPIO 

2

u/jacky4566 3d ago

IMO. If you are working on any small low power products SPI should 100% be preferred.

SPI Push-Pull design means lower consumption by nature because you only have to worry about line capacitance. With I2C you have line capacitance and active current drain while LOW.

The higher bandwidth also means the CPU is not spinning IDLE waiting for data. Get your data, get the math done, go back into STOP0 states much faster. But also I2C FM+ is a thing with 2 bits more overhead.

We just did a pedometer application with accelerometer data bursts of 192B every ~500ms. Since this product also has SPI flash it was less routing overall.

Places I have worked prefer SPI and fallback to I2C for GPIO constraints, routing, or other reasons.

There is a much bigger list of factors that go into I2C v SPI of course, and its an old hammered out debate. I just wish people not to write off SPI too soon in their projects.

1

u/2N5457JFET 2d ago

pedometer

Are it's readings admissible in courts, or is it the same case as with variograph, that results can be easily skewed or misinterpreted and courts dismiss them as evidence of a crime?

2

u/jacky4566 2d ago

You should always cross reference with your E-meter and be sure to spool up the turbo encabulator for the best results.

1

u/TechE2020 2d ago

You also run the risk of being out of a job because SPI just works.

1

u/juaspo 1d ago

Yea since bandwidth isn't a problem and we are a bit short on pin, using I2C would be the way to go here for us.

2

u/Real-Entrepreneur-31 3d ago

Some modules have open solder pads that you can short to change the adress. If you use multiples of the same LCD for example.

2

u/zydeco100 3d ago

You standardize the components used and wire them up to have known addresses. You're confusing a "unique address ID" like an Ethernet MAC with the I2C address scheme, which is a single byte. You can vary the I2C address of a part - sometimes - by changing how certain pins are ground in the design. But then those parts and addresses should never change once you hit production.

2

u/commonuserthefirst 3d ago

If you only have two conflicting devices for the same address there is a trick, that has worked for me before, I'm sure I'll get lots of reasons why this is bad but in practice it has been ok.

Put one device on the i2c bus as normal, put the second one on with clock and data swapped, swap the SDA and SDC in software when you want to read the second device.

Otherwise, some devices, like the laser TOF VL53L0X devices don't have solder the address solder pads, but can have address changed by software, until next power up. In that case you just need extra VCC lines used like chip select to wake them up one at a time and change the address, then next one etc.