Dynamic Slave Address Assignment?

M

Thread Starter

M

Okay, Modbus sounds perfect for my M2M application, communicating between master and numerous slave microcontrollers over an RS485 multi-drop link.

What if one of my slave controllers fail in service? Do I have to do a site visit to configure the replacement slave device with an address?

I hear some Modbus slave devices adopt a default address at commissioning, and are able to have their addresses configured by the master upon their discovery. Where can I find out how to do that?

M.
 
S
If you're writing the microcontroller code, I guess all you would have to do would be to listen on the default commissioning address, accept a register write to a specific register of the address the master wants you to be, and then start listening on that address.

It means someone there is going to have to tell the master via MMI or whatever which unit failed and has been replaced, so the master knows it has to initialize the new unit, and who to tell it to be.
 
Hi Steve,

Thanks for the valuable input.

They seem to want me to come-up with a system of slave address assignment that is performed for all the 20, or so, slaves at power-up. Gasp!

How does this sound to you? Each slave comes up at the same default commissioning address that you have described, then the master does a register write to that address for each of the slaves to be re-assigned. All the slaves receive the register write, and then each generates a bounded random response delay. The first to acknowledge the write gets the address, and all the slower respondents abandon the write upon detecting an active bus.

Now, I know that's not going to work properly, but would such a strategy warrant the necessary refinement? Unless there's an established method for tackling such a process, then I think I may have to hack my own solution. Crumbs!

M.
 
L

Lynn August Linse

As Steve mentioned, most will define a Modbus register (say 4x01001, which is 100th register) which can be read or written with a new slave device.

There is *NO* standard way to do this - there is no common Modbus function named 'force new slave address'.

You can do this, document it, and then anyone who wants to use it would need to write that documented register to change the slave address.

If possible, a DIP switch or other external trick can be used to enable/disable this value. An ideal solution is a DIP switch which when on, causes the device to be 9600 baud and slave #1 (or 247). The DIP switch OFF means use the values programmed as Modbus registers.
 
Thanks Lynn.

Okay, I've got it figured-out. My master broadcasts a discovery initiation command to all unconfigured slaves. The slaves then fight for exclusive link access to report their 16-bit serial numbers, using a CSMA/CA collision avoidance scheme with a truncated binary exponential back-off timer. The master records a list of any successful serial number reports, and at the end of each of several discovery cycles, commissions known hardware by broadcasting a 'program device ID' command, paired with the intended target's serial number and assigned ID. Any slaves that are assigned an address at the end of a discovery round, then take no further part in the discovery process, allowing more data path availability for slaves that may have previously encountered corruptive serial number report collisions.

Bother, you're sure someone hasn't already implemented something like this? Urgh, effort!

M.
 
Oh, and the initial periods of clear channel assessment that the slaves do prior to replying to a discovery broadcast message with their serial codes, are staggered by a small factor derived from a low-order grouping of their serial number digits. Slaves that are represented in earlier segments of the serial code progression get first shot at claiming the communications media for identity reporting.

Good approach, bad approach, comments highly welcome and greatly appreciated.

M.
 
L

Lynn August Linse

> Bother, you're sure someone hasn't already implemented something like this?
> Urgh, effort!

Sure, dozens of times this has been 're-invented' by various closed and open protocols. However, Modbus doesn't support it, so anything that you create makes your product no longer Modbus.
 
> Sure, dozens of times this has been 're-invented' by various closed and open protocols. However, Modbus doesn't
> support it, so anything that you create makes your product no longer Modbus.

Okay, thanks Lynn.

After speaking with the Boss, turns out plug-and-play address assignment may not be so important for this job, so CSMA/CA can wait a bit. Interesting subject, though. I noticed someone doing collision detection on an 2-wire, RS485 multi-drop, but the implementation details were concealed within their driver.

Okay, FreeMODBUS looks like a well developed and standards compliant solution for a server. Anyone able to direct me to a similar source code offering for a client implementation?

M.
 
Top