> For my project that uses an RS485 network I was planning to use a token > ring system so I don't have to deal with collision detection. That's going to be tough because RS-485 is a multidrop bus, not a ring. You could implement a ring from individual point to point RS-232 connections, but that would require two UARTs per node. > The solutions I've seen posted so far (and on piclist.com) all seem to > be of the bitbang variety. Since I'm using 16F877's for this project it > seems like a waste to bitbang stuff when I have a nice USART to use. Has > anybody done this yet? I'm not exactly sure what your question is but, yes, of course, many people have written code for the built in UART. I've done this many times myself, including some RS-485 bus applications. > I'm thinking that if I leave the receiver enabled > (im using a max487) the USART should receive a byte for every byte that > it sends. If the two bytes are different a collision has occured. RS-485 isn't designed electrically for this sort of thing. For one thing, the local node may see its own output signal correctly, but other nodes that are also driving the bus might not. Secondly, multiple transmitters can cause high currents. Basically, I wouldn't do this. > Second, whats a good way of handling back-off > and retransmission? RS-485 isn't suited for this. If you want arbitrary peer to peer communication with no master, look into CAN. It is designed for exactly this kind of operation. > If all the devices are set for the same back off time, or time > increment, they'll just collide again. I guess I could implement a > random number generator, but I'd rather not. Is there a good way to > handle this? > > How should retransmission be handled? Obviously the sending device needs > to retransmit the lost data, but how does the receiving device know that > a collision has occured? If it doesn't know there's been a collision it > might think the corrupted data is valid. This wheel has already been invented a few times. Check out how ethernet and CAN do it, or the "global serial bus" on some Intel embedded processors like the 80C152, although I don't know if that last one is still supported. ******************************************************************** Olin Lathrop, embedded systems consultant in Littleton Massachusetts (978) 742-9014, olin@embedinc.com, http://www.embedinc.com -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics