Connecting multiple PICs?
Moderators: David Barker, Jerry Messina
Connecting multiple PICs?
I'm looking to connect a number of PICs together in a Master -> Multiple Slave arrangement using the hardware UART.
The Tx pin of the Master would be connected to the Rx pin of every Slave. Using address detect would allow each Slave to know when the Master is talking to it.
The Tx pins of every Slave would be tied together and connected to the Rx pin of the Master.
My question is, from an electrical standpoint, is the above arrangement okay? I'd design the software so that no two PICs should transmit at the same time but if something goes wrong and they do then will it fry the PICs? I've looked at the datasheet but can't figure out exactly what's happening behind the Tx pin. If one PIC tries to take the Tx line high and another takes it low, would that cause a short-circuit between VDD and GND?
Can I simply wire the PICs together as outlined above or do I need to be a bit more clever about it?
Cheers,
Andy.
The Tx pin of the Master would be connected to the Rx pin of every Slave. Using address detect would allow each Slave to know when the Master is talking to it.
The Tx pins of every Slave would be tied together and connected to the Rx pin of the Master.
My question is, from an electrical standpoint, is the above arrangement okay? I'd design the software so that no two PICs should transmit at the same time but if something goes wrong and they do then will it fry the PICs? I've looked at the datasheet but can't figure out exactly what's happening behind the Tx pin. If one PIC tries to take the Tx line high and another takes it low, would that cause a short-circuit between VDD and GND?
Can I simply wire the PICs together as outlined above or do I need to be a bit more clever about it?
Cheers,
Andy.
Thanks for the reply.
Did a bit more reading and I can see three options:
1) Connect all the Slave Tx pins and the Master Rx pin together but make sure that the Slaves have their Tx pins set to input when not transmitting. Must make sure only one Slave transmits at a time or something might get broken.
2) Connect each Slave's Tx pin to the bus through an inverter with an open collector output and tie the bus high with a resistor. If two Slaves transmit at the same time it will cause bad data but it shouldn't damage anything.
3) Connect the PICs to the bus using a transceiver designed for the job - LIN / CAN / RS485 etc. Again, two nodes transmitting at the same time may corrupt the data but it shouldn't damage anything as the transceivers are built to deal with bus contention problems.
No. 3 seems like to be the best solution so I think I'll get some RS485 transceivers and have a play.
Andy.
Did a bit more reading and I can see three options:
1) Connect all the Slave Tx pins and the Master Rx pin together but make sure that the Slaves have their Tx pins set to input when not transmitting. Must make sure only one Slave transmits at a time or something might get broken.
2) Connect each Slave's Tx pin to the bus through an inverter with an open collector output and tie the bus high with a resistor. If two Slaves transmit at the same time it will cause bad data but it shouldn't damage anything.
3) Connect the PICs to the bus using a transceiver designed for the job - LIN / CAN / RS485 etc. Again, two nodes transmitting at the same time may corrupt the data but it shouldn't damage anything as the transceivers are built to deal with bus contention problems.
No. 3 seems like to be the best solution so I think I'll get some RS485 transceivers and have a play.
Andy.
I have done a multiple PIC system using the method Steven described, its very reliable if you have full control of the TX/RX timing.
Also the newer J parts can have open modes which allow the pullup device in the PIC to be switched off and it can be replaced by a resistor which will give you the open baud mode you require.
Also the newer J parts can have open modes which allow the pullup device in the PIC to be switched off and it can be replaced by a resistor which will give you the open baud mode you require.
Thanks dman. I haven't cancelled the order for the RS485 drivers and I'll be having a play when they arrive.
At the moment I only need very short range comms so I think the in-line resistor method will suit my needs. At the very least it will let me get on with figuring out the addressing and other protocol issues whilst I wait for the drivers to arrive.
If I can't replicate Doj's success or I need greater range then I'll take your suggestion and go for a RS485 system.
At the moment I only need very short range comms so I think the in-line resistor method will suit my needs. At the very least it will let me get on with figuring out the addressing and other protocol issues whilst I wait for the drivers to arrive.
If I can't replicate Doj's success or I need greater range then I'll take your suggestion and go for a RS485 system.
After spending too long being distracted by other things, I finally sat down and tried to get this to work.
I couldn't get the ‘resistor on the Tx pins’ method to work as I couldn't find a way to make the Tx pins of the non-transmitting Slaves an input whilst keeping the UART enabled to allow them to receive. With their Tx pins left under the control of the UART, each Slave drives the Tx line high when idling so none of them can talk to the Master.
Have I missed something simple? Is there a way to use the hardware UART to receive whilst keeping the Tx pin in a high-impedance state?
After some trial and much error I now have an alternative which seems to work. I ended up with a one-wire bus which is tied high (via a resistor). Each PIC has its Tx pin connected to the bus via a diode (cathode to Tx pin) meaning that it can only pull the bus low. The Rx pins are connected directly to the bus.
So far it seems to be working fine and I have three PICs merrily chatting away to each other.
Cheers,
Andy.
I couldn't get the ‘resistor on the Tx pins’ method to work as I couldn't find a way to make the Tx pins of the non-transmitting Slaves an input whilst keeping the UART enabled to allow them to receive. With their Tx pins left under the control of the UART, each Slave drives the Tx line high when idling so none of them can talk to the Master.
Have I missed something simple? Is there a way to use the hardware UART to receive whilst keeping the Tx pin in a high-impedance state?
After some trial and much error I now have an alternative which seems to work. I ended up with a one-wire bus which is tied high (via a resistor). Each PIC has its Tx pin connected to the bus via a diode (cathode to Tx pin) meaning that it can only pull the bus low. The Rx pins are connected directly to the bus.
So far it seems to be working fine and I have three PICs merrily chatting away to each other.
Cheers,
Andy.