arduino master-slave with serial library and rs485

Dear All,

I've been searching a lot about how to create a arduino master-slave network. Goal is to have a system where a master can send commands to the slaves and asks for data from the slaves.

I would like to do this with the Serial library(can also be softserial). I have an I2C network going. But it's limited because of the wire length. Because of that i've been working on extending the serial connection with a max 485 chip. That works. But only one way if you don't change the transmit/receive state of the chip because it's half-duplex.

My question is; did someone write a library similar to the i2c wire library but to be used with the serial connections of the arduino? This would be nice half-duplex but can also be full duplex.

I'm new to this and in need of a simple send-receive system. I know about the existance of protocols and things like that. But I don't have enough knowledge to really get in to it and master it.

Thanks in advance,
Rob.

Here's a site that explains one way to do it.

You want to multi-drop several boards on one or two wires using RS-485 or LIN drivers or something similar. Sounds like you're already using 485 so you need to control the transmitter enable at both ends so only a single transmitter is enabled at once.

In a nutshell the master enables its transmitter and sends a couple of bytes indicating the address of the slave it wants to respond and maybe a command. It then disables the transmitter an listens for the slave to respond.

The slave responds then the master moves on to the next slave.

However there are gotchas, for example what happens if the slave doesn't respond, what if the data gets corrupted and the slave opens the door instead of closes it, etc etc.


Rob

Hey Guys,

Thank you very much. I used the example at real2 electronics to create my rs 485 setup. The code is alright but a bit 'out of my league'.

I'm familiair with the idea of how the master handles the slaves one by one. But is there a library or an example of someone who has written something that finished? I cannot imagine that all arduino master-slave networkers have writter their own waterproof system.

I'm looking for something like the wire library but not for I2C(I've already got that to work), but for a serial connection.

Thanks.
Rob