Electrical – One master to 32 slave pic microcontroller communication, bitbang

bit-bangi2cpicserial-busspi

I'm trying to communicate with 32 microcontrollers (PIC 12f675). These are used to control 32 DC motors and 2 sensor for each PIC. So only two pins are left to communicate with master device.
I want to send signals (how much rounds to rotate and direction) to these 32 slave PICs in one master device.

PIC 12F675 hasn't I2C or SPI hardware. So I want to communicate with some bitbang technique. (PIC 12F675 running at 4 MHz internal clock)

What is the best way to do that?
(I prefer to use C language (xc8))

Best Answer

If wiring permits, the simplest approach is to have one wire which is an output from the master to all slaves, and the other of which is a return wire shared by all slaves to the master, and give each slave a separate "hard-coded" address which is also hard-coded into the master. Using such an approach and having each slave communicate only when spoken to will eliminate the need for arbitration.

If you have any sort of periodic interrupt in the master and slave, I'd suggest using normal UART-style communication with the additional proviso that the traansmit line will be idle for at least 12 bit times before any command, but all the bytes of each command will be sent consecutively with at least 1.1 but no more than 5 stop bits between them. Then any slave that decides a command isn't of interest to it can ignore everything that happens unless or until it sees the line idle for at least 10 bit times.

The data return wire could be implemented using an open-collector/open-drain approach (use a pull-up resistor, and have slaves pull down the wire when they want to send a "0" and leave it floating when they don't), but that would be slow and sensitive to noise. Speed and noise immunity could be improved by not using open--collector/open-drain approach, but instead having nodes include a circuit like the following on their output wires:

schematic

simulate this circuit – Schematic created using CircuitLab

If the PIC drives the output high, the bus will be driven high, and likewise if the PIC drives the output low. If the PIC leaves the output floating without any internal pull-ups enabled, which it should do whenever it has nothing to say, other devices on the bus will be able to pull it high or low without impediment.