Addressing scheme for RS485 stubs or "slaves"

techElder

Well-known member
I'm evaluating ways to create addresses for "slaves" (not i2c for me, but could be for someone else) in an RS485 system with a single master.

There are jumpers, switches etc. available so the user can set a slave to a particular address, but that takes some education. Also, this kind of hardwired addressing requires more pins from the PICAXE.

I've even considered an analog method with a resistor chain using ADC on one pin.

EDIT: Typically there could be 32 to 128 "slave" devices.

EDIT: If these devices were mass produced, it might be burdensome to give each one a predetermined s/n. Really, the only need for "uniqueness" is within the local network of devices.

What say you?
 
Last edited:

hippy

Technical Support
Staff member
It probably depends on how many slaves you allow, what the ultimate goal is.

They could be pre-programmed with an ID in EEPROM so no need for external I/O or they could use a Dallas 1-wire device or other chip with a serial number to obtain a unique ID.
 

inglewoodpete

Senior Member
I once created a network with 64 slaves. Using 2 ADC inputs and a 6 way DIP switch, it was simple to use 2 x ADC channels to read 1-of-8 values each. 8 x 8 = 64 unique addresses.
 

techElder

Well-known member
Typically there could be 32 to 128 "slave" devices.

If these devices were mass produced, it might be burdensome to give each one a predetermined s/n.

Really, the only need for "uniqueness" is within the local network of devices.

The single pin ADC method is where I'm leaning, but I really want to do something "automatic!" :)
 

hippy

Technical Support
Staff member
The greater problem is that, no matter how automated or not ID assignment is, one usually needs to know where each module is physically located and/or what its function is to know what it controls and which to read from and send to. There will always be some extra level of complexity and ID mapping required.

Knowing that can affect how you view what means of identification you need and mechanism to use.
 

rs2845

Senior Member
Im currently designing something similar for an alarm system.

Each device (up to 126) will have a unique serial number and a relay which breaks the connection to other devices until it's address is defined during the auto learn procedure.

The master makes a request, which the first device on the loop acknowledges. It will then return its device type, current state and serial number. Once the master receives this and is happy it will make that device toggle it's relay and go to sleep, so the process can continue on the next device. All the way until the loop reaches end 2 on the master.


Ive tried this with about 8 devices so far and it worked flawlessly. I'll try dig out the code,I did it with RS232 though and there was a separate power bus.
 

techElder

Well-known member
Hippy, yes, I've had that "chicken-or-egg" discussion with myself quite recently. :)

rs2845, you said, "the first device on the loop acknowledges". How does the "first" device know it is the first device?
 

Buzby

Senior Member
As hippy says, it's not so difficult to auto-address a bunch of identical slaves, but that won't tell you where each is physically slave is located.

Three solutions spring to mind.

1 - Rotary DIP switches to set the address of each node. ( Rotary are easier to understand than DIL. )

2 - A simple display on each node, showing what it's auto-configured address is.

3 - A pushbutton on each node. At initial system initialisation the user goes round pressing each button in turn, thus populating the node list in a known sequence.

It really depends on whether the system need to 'know' that each node is in a specific location, or if it is the fact they thay are unique that matters, and where they are is irellevant.
 

techElder

Well-known member
If I used a pushbutton on each node, then both parameters can be assigned: 1. the master sends the "s/n" to the node with the button pushed; 2. the user at least knows the sequence of pushing buttons and what order the nodes were in at that moment. Some display could be an addition.

Hmmmm. That's promising. Thanks, Buzby!
 

hippy

Technical Support
Staff member
3 - A pushbutton on each node. At initial system initialisation the user goes round pressing each button in turn, thus populating the node list in a known sequence.
I quite like that idea and it would be very easy to implement.
 

rs2845

Senior Member
rs2845, you said, "the first device on the loop acknowledges". How does the "first" device know it is the first device?
I had a routine where the devices were first powered it entered the auto learn mode. All the devices enter that mode but only the first device will be able to talk to the master because the wiring to the others are cut by the relay.
 

Buzby

Senior Member
And now, ... Option 4 !.

This uses cheap hardware, but needs a lot of programming. However, it's just so cool you've got to give it some thought.

1 - Fit each node with a phototransistor.
2 - Put a BlueTooth module in the Master.
3 - Use a smartphone to flash a node number to the phototransistor, at the same time relaying the GPS co-ordinates to the Master.
4 - Bask in the warm glow of admiration for your skills.

( 7.5% royalties will be quite acceptable to me. )

Cheers,

Buzby
 

techElder

Well-known member
Yeah, Buzby, the folks around you are just amazed that you haven't been properly rewarded for the momentous ideas that you can float. :rolleyes:

I'll send your royalties to you from the poor house! :)

PS. I am seriously working on your third option, though, and am glad you floated that one in the public domain! <GRIN>
 

techElder

Well-known member
Application of Slave Addresses in an RS485 network

A possible scenario for the application of slave addresses:

Note: All units power up in autonomous mode; not master, not slave. There is a separate unit that is the Master Unit with display, alarm and etc.

  1. Power up the Master Unit.
  2. Power up the "next" unit on the network while holding down the "get address" button.
  3. Unit is in "receive" mode waiting for an address from the Master Unit.
  4. A "command" is transmitted on the network that the Master Unit interprets as "Create, Save and Transmit an address to the network". Wait for Acknowledgement.
  5. The "next" unit receives this address and Acknowledges receipt.
  6. Address is stored in EEPROM on the "next" unit.
  7. "Next" unit is reset. {button is released}
  8. Address is read from EEPROM as part of power up sequence.

Go to "next" unit and repeat.
 

rossko57

Senior Member
Avoid the button by having a default address. Assuming the Master is effectively address 0, all slaves are manufactured at address 1. When a slave powers up, finds itself to be address 1, it squawks to be assigned a new address from the master's list of availables. And remembers that to EEPROM.
Or, if the communication protocol is Master-polled, the master can poll the default address periodically looking for new "blank" slaves. (This makes bus arbitration simpler, as you talked RS485)

You might still want a button or link to "reset factory defaults" though, could also include non-addressy things depending on the device.
 

techElder

Well-known member
Avoid the button by having a default address.

That could work, too. Let's see:
  1. Power up the "next" unit on the network. (No other units on.)
  2. Unit is in "receive" mode waiting for a command from the Master Unit.
  3. Power up the Master Unit. The Master Unit sends out a "status" command to unit with address "1" (default).
  4. If it gets an appropriate response, it sends out a command with the address chosen for the unit addressed as "1". Waits for Acknowledgement.
  5. The "1" unit receives this address and Acknowledges receipt.
  6. Address is stored in EEPROM on the "1" unit.
  7. "1" unit is reset.
  8. Address is read from EEPROM as part of power up sequence.

That's a lot of clunky the way I wrote it, but it certainly could be refined.

Certainly not a bad idea. Thanks!

EDIT: On further reflection, the "default" address on a new slave unit will naturally be "0" that is initialized in the EEPROM. Should use that.
 
Last edited:

rossko57

Senior Member
So much depends on the communication protocol you are inventing, alongside this. Often address 0 is reserved to mean the Master, or as a means to broadcast to all connected slaves simultaneously (like an emergency STOP), or ...

How fancy your address-setting solution needs to be, will depend on whether it has to work in a live running environment (there's no reason that it cannot) - e.g. introduce a new addition to an active working system without interruption.

The decisions are yours!
 

techElder

Well-known member
First I started looking at MODBUS, but that's way overkill for what I'm doing.
I'll only be passing a few "commands" back and forth (more like remote procedure calls) to no more than 16 devices within 100 feet.
Thanks for the advice!
 

Svejk

Senior Member
Typical industrial procedure for large field networks, with nodes that are running well into hundreds, is to use a programming tool. That is, the master is taught a network configuration and the slaves are programmed with the address using a purpose build tool. Also, generally, the master is used to send/receive information from field and relays data to a controller, otherwise the controller might use most of CPU time updating data from/to field.

Some form of fault/missing nodes mechanism we'll also need to be put in place to avoid 'ghost' data.
 
Top