> Well, someday I'm gonna build that dream house and, while I dream, I'm > constantly coming up with new ways for complicating things. I would like > to build an RS485 based network to connect various gadgets throughout the > house. So I've been doing a little reading and I have a few questions. I > thought I would post what I have in mind for review to make sure I'm on the > right track. I have been thinking of this myself. Since I have some experience with RS485 communication, that would probably be my selection too. > > First, I figure I'll have a master node that provides the link between my > PC and the RS485 net. At this point, to keep it simple, I figure the > master can poll slave nodes to avoid collisions. In addition, the master > can store configuration data, etc. so that the network can operate without > the PC. The PC itself could be the master node. > > This brings up my first question. Should I go with half duplex chips and > forget about it, go with full duplex chips but use half duplex > communication for now to keep my options open, or is there a simple means > of implementing collision detection and do you think that I should bite the > bullet and set it up as full duplex communication from the get go. If You use full duplex chips You can allways select half duplex later by connecting RX+ to TX+ and RX- to TX- externaly, so I would go with the full duplex for the hardware to make it more versatile. With half duplex there is the possibility to have collision detect in software since all slaves can listen to what the other slaves sends. There is still the possibility though, that two slaves will try to access the bus at the same time which still would cause collision on the bus. Therefor some sort of acking from the master should be included in the protocol to let the slave know that its message has successfully been transmitted and received. In half duplex mode, the master also has to follow the collision scheme (which could mak e the master programming harder). Another way to do it is to let the master initiate a broadcast from slaves that needs attention. The master sends a 'anybody got something to say' message and the slaves have fixed time slots, depending on their address, to send a reply in . This would work in both half and full duplex, but would require a good response time from the communication routine. When the master sends this command it can be sure that, after some maximum (known) time, all slaves that needs attention has replied. The reply kan be short, just a status byte letting the master know that it needs attention and the master can come back to this slave after the broadcast messages from all slaves has finished. This could also be a way to automaticaly let the master know if a slave is present (working) or not (maby even to let the master know that a new slave has been connected). A third way is to have full duplex nodes, but the nodes connected in a ring, TX+,TX- from master goes to RX+,RX- on first slave, TX+,TX- on first slave goes to RX+,RX- on the second slave and so on to the last slave where TX+,TX- goes to RX+,RX- on the master. This would mean easy communication programming in the master but harder in the slaves, and if there is a lot of slaves, very much of the processor time for the slave would be used for communication. Another problem is that the whole network is down as soon as any slave isn't working. > > The only thing I don't like about polling in a master/slave relationship is > that it's kinda like a uC without interrupts. I don't mind using a > master/slave setup, but I _would_ like a way for a slave to tell the master > it needs attention. Maybe I could use one pair for half duplex RS485 and > the second pair as some sort of attention line ? Any ideas ? I once did a project with a 485 network with up to 32 nodes, where every node would send a message spontaneously once every 2 seconds. It was important that there where no collisions and that the message was sent whith as short delay as possible from when it was initiated in the slave (a RF-tag reader). Here I used a separate 'Bus busy' line, a simple open collector transistor circuit which every node could read and assert. Whenever a node needed to send a message it checked 'Bus busy' line and if it was free it could assert the line , transmit and when finished, release 'Bus busy' line again. If it wasn't free it had to wait until it was free, do another delay depending on it's address so that not two nodes that waited for the line, would access it exactly at the same time. This scheme still did cause some collisions (caused by two nodes want ing to assert the line at exactly the same time when it was free), not many but enou gh to be unacceptable, so I modified the asserting of the 'Bus busy' line as follow s: Whenever a node wanted to transmitt and the 'Bus busy' line was free, it asserte d it, did a short delay depending on its address, released the line again for a ve ry short time. During this time it read the line and if it where free it could be s ure that it had the bus for itself, reasserted 'Bus busy' again and transmitted and released the line. If two nodes where to assert the 'Bus busy' line at the same time it would here be the one with the highest address that got access to it. This turned out to work very well. The problem with this is that the communicating requires access to some pretty accurate timing - which may not be a problem since when there is need to send some info the processor has allready finished its (possibly) time critical routines. Another problem is that this communiaction connection is no standard and could cause trouble if already existing devices where to be used. In the case of home automation I would probably go with the full duplex wireing and master polling slave nodes. > > Next is the wiring. I am planning to use twisted pair CAT5 cable. As I > understand it, I'll only need one pair for half duplex or two pair for full > duplex. That leaves two unused pair. So my thoughts turned to using the > extra wiring to carry power. What are your thoughts on this ? > > There are some devices that will use 5V and some that will use 12V. Am I > asking for trouble if I use a power supply that outputs both 5V and 12V and > put them both on the unused wiring ? What kinda of gotchas will get me > ? > > This isn't mission critical stuff but, at the same time, I don't want to be > working on it all the time either so I'd like to build reliability from the > ground up. > > Any thoughts appreciated.. > > Eric Don't forget the common wire for the RS485. Of course this will be the GND wire if You supply the nodes from one source (unless the RS485 is optically isolated, which I see no need for if there is a common powersupply anyway). Be sure to put some spike absorbers (600W transorbs and 100 ohm resistors) and small filters on every RS485 line. Good luck and let me know what You come up with. ============================== Ruben Jvnsson AB Liros Elektronik Box 9124, 200 39 Malmv, Sweden TEL INT +4640142078 FAX INT +4640947388 ruben@2.sbbs.se ==============================