2
\$\begingroup\$

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?

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ Do I need additional CAN bus transceivers even though my micro controller supports CAN protocol? I tried searching for CAN transceivers on digikey and found out that most of them are 5 V type. Is it common for them to run on 5V? Is 3.3V a rare case for CAN? \$\endgroup\$ – Whiskeyjack Sep 27 '17 at 7:06
  • \$\begingroup\$ @Whiskeyjack I'm not sure...it's possible some microcontrollers build in the transceivers. The ones we've used need an external transceiver yet. Regarding 3.3V transceivers, TI SN65HVD232DG4 is one. It's available at Mouser. \$\endgroup\$ – 1N4007 Sep 27 '17 at 13:17
  • \$\begingroup\$ Thanks. I'll take a look into it and check the feasibility. :) \$\endgroup\$ – Whiskeyjack Sep 27 '17 at 13:19
1
\$\begingroup\$

Your polling solution is probably the most classic.

One other solution is to do a broadcast poll.

Basically send a message that everyone hears which causes them to send a pulse a set delay after receiving the poll if they have data. The delay length being set by the devices address.

The master can then monitor the return signal and decode who has data to send and ask it directly.

Another technique is to build in a short delay between master transmission and slave acknowledge. Then use that window to allow slaves to squawk a single pulse that acts like an interrupt to the master. You would then need to poll them.

\$\endgroup\$
  • \$\begingroup\$ Broadcast thing seems interesting. I will give some more thought to it. BTW how difficult do you think it will be to set a custom slave address for a general microcontroller? Arduino UNO (atmega328p) is pretty easy. \$\endgroup\$ – Whiskeyjack Sep 26 '17 at 19:34
  • \$\begingroup\$ @Whiskeyjack ya the address is always the issue. There are ways you can set random addresses but it gets complicated quickly. \$\endgroup\$ – Trevor_G Sep 26 '17 at 19:39
  • \$\begingroup\$ @Whiskeyjack some sort of collision detection is usually required too. \$\endgroup\$ – Trevor_G Sep 26 '17 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.