=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Date: Wed, 23 Feb 2000  11:06:19
    From: Nikolai Golovchenko 
      To: pic microcontroller discussion list 
 Subject: Re: Multi-Master, half duplex protocol w/ collision detection
--------------------------------------------------------------------------------

Hello Adam.

When you need multi-master network with collision detection, CAN
network comes to mind. The good thing is that you can use an RS485
transceiver to imitate the very nice arbitration mechanism of CAN,
without having to buy more chips.

1)CAN uses passive(high) and dominant(low) bus states.
     RS485 transceivers can do it. Just tie driver enable(low active)
     to TX output of PIC, driver input to 0V, and connect receiver
     output to RX input. RS485 transceivers treat floating bus
     state(passive state) as high.
2)To send data, node waits for bus to be free for some fixed interval
(minimal pause between messages) and then starts transmission. This
alone solves most arbitration problems. For cases when several nodes
start transmission at the same time see below.
     Poll RX input in this interval frequently enough to catch any
     bits.
3)In CAN, message ID is transmitted first. ID also serves to tell which
node has higher priority. If a node sends passive bit(1) and sees a
dominant bit(0) instead, it releases the bus to allow the other node
with  higher  priority  to continue transmission. At the same time, it
doesn't stop receiving data.
     PIC will have some extra work during arbitration phase. While ID
     is being sent, you should poll the RX line state before the end
     of each sent bit. If it detects zero instead of one then other
     node   dominates  the  bus. Stop transmission immediately. If you
     clear SPEN bit the receiver also turns off. May be clearing
     TRISC<6> bit will work(?).

You can find additional information on CAN at  www.can-cia.de

Hope it helps.

 Nikolai

On Tuesday, February 22, 2000 M. Adam Davis wrote:
> Well, I'm still working on my home automation terminal, and have come to the
> point where I need to decide on a protocol to use for talking on the rs-485
> network.

> Preferably, I would like it to be multi-master, half duplex and have collision
> detection.  I know of only one easy method for collision detection, which is to
> send the start character first, then the priority code, MSB first.  In the low
> points of the priority code, I need to check the line to see if another node is
> driving the line high, and thus has a higher priority code than me, and I cease
> transmitting.
[snip]