RS485 auto config!

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all
I have a master with 32 salve on RS485 bus.All the salves are the same sensors.my problem is how to address them automatically.I mean not hardcoding a seprate address for each salve in software.How my master can distinguish between them.Is there any idea or protocol?

Thanks in advance.

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You will need to assign a unique address to each slave. The slaves all listen to the master for their address. When one of the slaves recognizes its unique address it is allowed to talk to the master. Otherwise you would have to design hardware to allow the master to address the slave of interest.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Further if you have no intelligence on the slave end then it seems you would have to implement a 5 to 32 decoder select system on the master end to enable the slave of interest to talk to the master. look at a 74138 decoder or like IC for a decoder. If you do not use a decoder then you would need 32 I/o lines to do the select. Using a decoder reduces that down to 5 I/O lines.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Huh. Well, if you don't want hard-coded addresses, the slaves could come up with some random 8-bit number as the address, and if two slaves see that they have the same address, they come up with another random number, until there is no conflicts.

Or another way could be that a slave has some global configuration address, and first you must configure it to some address, that is stored to EEPROM. Downside is that there must only be one slave listening for the config data, until all are configured.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Usually manufacturers use dip switches, but there are some intelligent methods of doing this.

An auto method of giving unique IDs to same type devices, can be achived with software only, but with the disadvantage that you won't know each device ID. For example if the 32 slave devices are smoke sensors and the master is a BMS system, then how could inform the maintainer of which room is on fire.???

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is not clear that the sensors have any intelligence or not. If they have none then you have to do a hardware select from the master.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There must be some intelligence, because the OP told us that each slave is a part of a network. This means that there must be a CPU device (or something). If there is any intelligent programmable ic, there for sure some more bytes would solve the problem.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are the sensors a readily available product, or is this something you still need to design and you are now in the concept phase?

I once spoke someone who had designed such automatic address assignment method, but I don't know the details.

What is the exact requirement? No need to set address switches? No need to have some unique identifier inside each sensor? If you look at the Dallas One-wire protocol, it has a discovery scheme where slave addresses are gathered by sending request to slaves to respond if a certain bit of it's unique ID is set. This way you can discover all the connected slaves and their unique IDs.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First, please be aware that RS485 is a hartdware-only spec, like RS232. There is nothing about baud rates or addressing or anything else like that.

If you want NO presetting of the slaves, then the only option is to have the master send to the slave a "change address" command. You might do it this way: All slaves have a default address which is the same for all slaves. The master constantly "pings" the default address. As soon as a new slave is connected to the system, it responds to the ping and the master tells it to change to a new address of the master's choosing. This fails, however, if all slaves are connected at the same time (network is wired up, then, as the last action, connected to the master).

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim,

I don't think there is another way of doing this. This is the standard method. Does anybode knows something different????

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Personally, I would use a dipswitch or a header with jumpers.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DIP switches are the usual method but there are definitely some software protocols that could be used. First of all a slave needs to be able to do collision detection and then backoff for a random period before trying again. This is how Ethernet works (go read about it).

You could have one "slave" at a known address that is used to give out slave addresses. Each device comes online as a master and then tries to get an address from the address server slave. It backs off if a collision is detected. Once it is given an address, the node becomes a slave listening for requests from the real master node.

After some "startup time interval", the real master node requests the list of slave addresses that have been assigned from the slave server and starts to communicate with them. You can decide if you want the address server slave and real master node to be actually the same device.

You can also decide if you want to keep slave addresses persistently across power cycles or if they are assigned every time. If they are kept then it is still useful to talk to the address server at power up and register themselves (while doing collision detection).

This scheme should also work whenever a new device joins the network. I have left out some of the details (deliberately) but I think you can understand the idea.

--Mike

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Collision detection is a very good idea.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks all for your replies.
Actually I'm designing a BMS system and every slave have a mega8 device.so they all have intelligence!!! if you call this intelligence!

I think the collision detection is a good idea but how can i detect collision?

I love Digital
and you who involved in it!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The slave listens to what it transmits. You can do that easily with most RS485 interface chips. If the two are not the same, then you have a collision.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

google CSMA/CD

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How does one prevent each slave from selecting exactly the same back off time? You need some source of entropy.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The slaves need some quasi-random number generator. This is a very common need for CDMA (carrier detect multiple access) systems.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Would a free-running timer counter be of assistance here?

I mean the timers should be out of sync, as the power-up delays and oscillator frequencies are not identical, and even 1ppm error will guarantee that two different AVRs clocked at 1MHz will have at least 1 timer count of difference after 1 second.

It does not help much if two different AVRs have almost similar error, a very long time is then needed until timer tick counts differ.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe the OSCCAL register?

To be honest, I would simply program a slave address into the EEPROM; either during programming or with a special setup packet in a direct 1 to 1 connection.

Or use one of those one-wire silicon serial number ICs. Or serialize the firmware.

One maybe a ring topology where each slave receives the packet from a neighbour slave and retransmits it. Include a hop count in the packet and you can easily determine a slave address. Big disadvantage is that if one slave goes down the whole network goes with it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Almost one other method exist. If all devices are connected in ring, transmitter of one device to receiver of second, master can send specific command to first slave assigning its address to one, next this slave send this command to second, assigning its address to two, etc. Last device send this command to master, of course. After initialization phase, in normal transmission each device filtering received packets destined for it, and transmitting all other and his own packets to next device.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you're doing a BMS system, then why not go with an industry standard protocol? Some suggestions are BacNet and Modbus. Have a look at commercially available devices similar to what you're doing and see how they've solved the problem rather than you learning the hard way?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have slave sensors, then surely it matters which sensor is which. e.g. if they are alarm switches, it matters if they are on door #1 or window #6. If the sensors somehow create or are assigned random addresses, how will you deal with this issue?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

you could put one slave after another on the net.