>I have a small RS485 two-wires network with about ten nodes. I have a
>master that initiates the communication on the bus. All the other nodes
>are always in receiving state and start transmitting only if the message
>from the master is addressed to them.
>
>A simple method to assign an address to a slave is to have a set of
>jumpers/dip-switch on the board, but during the installation/setup
>phase, the technician must be careful to avoid duplicate addresses.
In addiction DIP switches are unreliable in harsh conditions.
>I'm thinking about an alternative method to implement in the master
>that, during the start-up phase, assigns automatically the addresses to
>the slaves.
>However, at the moment, I didn't find a good solution.
>
>Any suggestion or experience on this topic?
If the master has persistent memory and each slave is initially known
slave address (say 255), build the network by adding one node at a
time (e.g. by powering up the devices one by one). The master checks
for slave 255 and assigns it an other slave address. This is repeated
for all slaves.
If a faulty node needs to be replaced, the new replacement unit is
again at address 255 and the master then commands it to the same slave
ID as the original device.
If each slave has a unique vendor:serial_number, either readable
through the ordinary bus or some configuration port there are various
methods.
The address data base could be done by adding one device at a time, as
in the previous case or using some off-line configuration (running on
a laptop) to run a point-to-point connection with a new slave, either
to the network port or through some configuration port and command the
slave address.
Take a look at CanOpen Layer Setting Services (LSS).
-----
If the slave has a unique vendor:sertial_number, generate a hash code
and use it for slave address. The master runs through all possible
slaves by asking e.g. "Slave 37, report your serial". If there is a
timeout, none is there, if there is a garbled reply, there is a
duplicate, there is a collision and if there is a clean response,
assign the address. Repeat the scans but ask "slave 37, report serial
except serial37" and if you got a response, force the slave address to
a free slave address.
If there still are garbled responses, refine your search "Slave 37
report your serial ending in 0" up to serial ending in 9. Of course,
this requires that you are able to differentiated between no response,
garbled response and valid response.