Electronic – Two way communication between one master and multiple nodes

communicationi2c

I have an architecture like this:

Architecture

Master – It contains an RF communication chip. All nodes rely on Master to receive and send data to a central unit.

Node – It has some basic GPIO functionality. There can be 4-5 different types of nodes, each requiring a different GPIO count. For the sake of design simplicity, I am planning to throw a cheap microcontroller on each node and handle all GPIO locally. That way I just need a pre-defined control data packet from the master to do any task. Similarly, the node will send a pre-defined packet which the master will understand. The packet definition will contain the node type.

Nodes can change in number and preferably should be hot-swappable. Communication works like this:

Two nodes do not communicate directly.

Master can have a data packet which it wants to send to any particular node.

Any node can have a data packet which it wants to send to the master.

Max distance between a node and master will be less than 50 cm.

After some thought, this is the plan I came up with:

Make all nodes communicate over i2c. 16 nodes per master seems to be a good number so I can put a 4 bit DIP switch to set the i2c address of each node. Basically I will be doing a digital read on 4 gpio and setting the address accordingly.

This will be perfect when master wants to read or write data to the nodes.

For the time when node wants to send data, I need to have an additional GPIO per node which alerts the master that some data is present. Alternatively, I can keep reading all nodes in the loop and keep checking if some data is available.

Is there a better solution to this problem?

Best Answer

An alternative to I2C, you could consider CANbus for this solution. It is arguably more complex, but slaves would be able to communicate back to the master on the same bus without needing a GPIO to indicate they have data available. Also, collision detection is built into the design of the physical layer and protocol.

CAN controllers are available relatively cheap, although you need a transceiver for each node.

Other common multidrop buses you could consider:

RS-485: Simple to use, but you would be responsible for all the addressing. I2C at least builds that in.

SPI: Useful if you have the I/O to spare for a slave select line for each node. Based on your description above, this would probably not be the best route.