Connecting multiple PICs?

Discuss PIC and electronic related things

Moderators: David Barker, Jerry Messina

Post Reply
AndyO
Registered User
Registered User
Posts: 48
Joined: Sat Oct 27, 2007 7:08 pm
Location: Beijing, China

Connecting multiple PICs?

Post by AndyO » Sat Mar 22, 2008 9:34 pm

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.

TimB
Posts: 262
Joined: Wed Oct 04, 2006 7:25 am
Location: London UK

Post by TimB » Sat Mar 22, 2008 11:15 pm

Your into the world of multi device 1 com line protocols. You can adopt a standard like Lin or Can or roll your own.

Sorry but reading some data sheets is the best way to go. Mchip have a few to get you thinking on the right lines.

AndyO
Registered User
Registered User
Posts: 48
Joined: Sat Oct 27, 2007 7:08 pm
Location: Beijing, China

Post by AndyO » Sun Mar 23, 2008 7:26 pm

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.

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Sun Mar 23, 2008 8:04 pm

I haven't tried this, so may be wrong, but would your first option be OK so long as you connected each Tx pin to the bus via a resistor? That way, the current would be limited if two Tx pins became outputs at the same time with high and low levels.

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Sun Mar 23, 2008 10:11 pm

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.

AndyO
Registered User
Registered User
Posts: 48
Joined: Sat Oct 27, 2007 7:08 pm
Location: Beijing, China

Post by AndyO » Sun Mar 23, 2008 10:27 pm

Cheers Steve and Doj.

Great news that a resistor on the Tx pin will work - I'll give it a go.

dman776
Posts: 115
Joined: Mon May 28, 2007 3:59 pm
Location: Texas

Post by dman776 » Mon Mar 24, 2008 2:08 am

Just another thought for you...

This is a classic case for RS485. It is multi-drop by design and very easy to work with.

AndyO
Registered User
Registered User
Posts: 48
Joined: Sat Oct 27, 2007 7:08 pm
Location: Beijing, China

Post by AndyO » Mon Mar 24, 2008 10:50 am

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.

AndyO
Registered User
Registered User
Posts: 48
Joined: Sat Oct 27, 2007 7:08 pm
Location: Beijing, China

Post by AndyO » Sun Jun 29, 2008 10:03 pm

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.

Doj
Posts: 362
Joined: Wed Apr 11, 2007 10:18 pm
Location: East Sussex

Post by Doj » Mon Jun 30, 2008 9:03 am

Great solution Andy, I can see no issue on localised comms with short distances, in noisy environments it might need a PFET in place of the diode.
The other way would be to use the soft usart if you only need lowish baud rates.

Post Reply