PIC to PIC communications
I have a system with 5 PICs all doing separate tasks in separate boxes. The PICs are in a peer to peer system with no master. All have equal priority and lose only a few microseconds checking bus activity every time through their main software loops. If a message is pending, all PICs need about 2 mSecs to work out if the message is for them.
The hardware has a 10 way ribbon cable linking all PICs over about 2 metres and only using a few pins. 4 PICs are 18F4620 @ 20 MHz and one is a 16F88 @ 4 MHz. Each PIC has a different ID stored in location 0 of the EEPROM. All comms is at 9600 bps. Slow man is the 16F88 @ 4 MHz. With just the 18F4620 I can get a reliable 50 kilobits.
I use 3 signal lines, plus power and ground. There is an ATTention line, and ACKnowledge line and a MeSsaGe line. ATT, ACK and MSG are tied to +5 volts with 10 K resistors and the PIC pins driving the communications bus are set as inputs. I have 220 ohm resistors on every PIC pin connecting to the comms bus to prevent damage if the software inadvertently sets rival pins to outputs. The 220 ohms also act as good line termination and suppress ringing.
In normal operation, when each PIC is doing its own job and not communicating, the MSG, ATT and ACK lines are all floating high with those pins set as inputs. The software in each PIC checks for comms activity at least once per loop.
When a PIC wants to send it checks that ATT and ACK are both high meaning the comms bus is free. If the bus is free it stakes a claim by setting the ATT pin to an output and pulling the ATT line low. That PIC immediately sends a continuous stream of address polls on the comms bus for as long as it takes for the target to finish it's own tasks and get around to checking the comms bus, or a timeout occurs.
Whenever any PIC sees the ATT line go low it checks the message line for their address. If the address does not match their own ID that PIC goes back to its normal tasks. The PIC that does match the ID being polled pulls the ACK line low. The sender sees ACK go low so it knows the target PIC is ready to receive. The sender stops sending the Destination ID and now sends the message. The sender keeps sending until it sees the ACK line go high. This means the receiver has a clean copy of the message. All messages are error protected with simple CheckSums.
The system works a treat. There are no interrupts needed.
HTH
BrianT