Address and communicate with multiple devices in a matrix

communicationmicrocontroller

I have a large matrix of devices, "nodes", that I would like to address and communicate with – assume > 50 nodes. Each of the nodes have a controller that receives data from a central microcontroller and then performs a function.

I was thinking of using I2C for this but since the controllers will be the same, the number of addresses are limited to only as many variations the controller can provide.
Is there a better way to address and communicate with this large grid of devices with minimal wiring? I initially chose I2C since it has just 2 wires (SDA, SCL) for bus functionality, apart from power and ground.

Best Answer

You are effectively describing a "single master, multiple slave" arrangement. When working with such a setup, the first two approaches that come to mind are SPI and I2C.

Personally, I veer away from SPI unless I'm only concerned with a small number of slave devices (low chip count), or it's the only interface available. This is primarily because you'll need a dedicated slave-select line for each slave device, consuming another GPIO pin on your MCU/CPU, or you'll need additional multiplexing circuitry in place to save your spare pins. The one added benefit of this is that you can "broadcast" to groups of devices at the same time (assuming they don't reply to you) rather than having to broadcast to the entire bus like you do with I2C.

I2C isn't bad at all, even for a large number of devices. If you want 50 slaves, you'll need at least one of:

  1. all of your devices to either support 6 programmable address bits (either via flashing it into the chips in advance or the use of Vcc/GND address pins)
  2. if your MCU/CPU has multiple I2C busses, you can split up groups of chips to share individual busses, allowing you to need smaller programmable address ranges
  3. select chips such that they use non-overlapping ranges of I2C addresses.

Additionally, I2C has the added benefit of being able to handle voltage mismatches easily if the master and slaves communicate at different logic levels (ie: 3.3VDC vs 5.0VDC).