This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TMS320F28335: How to set slave addresses dynamically in MODBUS

Part Number: TMS320F28335

Tool/software: Code Composer Studio

I am studying about MODBUS. So I am a beginner in this. Could anyone help me in understanding how addresses are assigned to different slave devices in MODBUS RTU when I am implementing MODBUS protocol using SCI module in TMS320F28335. Will it be like the Master will assign some values from 1 to 247 dynamically? It cant be predefined in all devices right? Could anyone explain in detail?  

  • Slave device address are typically static (in fact, I've never seen a dynamic slave Modbus address).  The reason for this is because you typically want to know exactly which sensor or device you are talking to without the overhead of discovering it dynamically.  Keep in mind that Modbus was around when 9600 baud was considered fast enough for most things.

    In many existing devices, the Modbus address is either set by DIP switches or by commands to a default address (typically address of 1 or 2).  Some devices, with a small display and buttons, allow you to set the address at the device - in particular many motor drivers (VFDs) are like that.

    Example of a Modbus enabled VFD:

    https://www.hitachiacdrive.com/wp-content/uploads/2013/05/NE-S1QuickReferenceGuide.pdf

    See chapter 8.  The Modbus address is set by manually setting it from the display on the device (Section 8.4).

  • HI

    Thank you for the response. I intend to use TMS320F28335 as my Slave and PC as my Master. How will I set Modbus address "by commands to a default address" as u mentioned? Could you please explain. I am a beginner in this. Isn't it that the Master should know the address of the slave so as to start the communication? So without the address Master cant start the communication right. So did u mean to say that the User should set some address in some register in the slave through slave code and store all these used addresses in the Master like a lookup table so that the Master knows which address belongs to which slave?

  • Take a look at...
    advdownload.advantech.com/.../UM-ADAM-4000_series-Ed0-1-EN.pdf
    page 23 (section 2.2)

    This gives an example where a device, by default, is address 0x01. When you first set it up, you are to connect it to your computer (and only it, no other devices) and give it the command to change its address. That is how you set the slave address of this device.

    Once that is done, then you can install it onto the network with other slaves with all unique addresses.

    ====

    Now to explain further, let's do a hypothetical story:

    Let say your device has two switches, one is "reset" and the other is "revert to default". If a user holds down "revert to default" when pushing then releasing the "reset" button, the device reverts all its settings to "factory default". This includes setting its slave address to 0x01.

    Now you connect that device to your computer and ONLY that device. You send a Modbus command to the device addressed to 0x01. The command tells the device to change its address to 0x42.  Your computer here acts as a Modbus master, but it is NOT connected to your system.

    Now you disconnect that device and install it to your system with many slave devices. This device you just installed should be the ONLY device with address 0x42. You go to your control station (Modbus master) and set it up to talk to 0x42. The device can now tell you that the pressure is 100KPSI and the plant is about to explode.  (Until you realized that the master software got the scaling wrong).

    Note that in above "your computer" and "control station" are two different things. The "your computer" should be a separate computer that is NOT connected to the system with many slave devices. The "control station" may be a computer controlling a chemical processing plant, which has many slave devices.

    ======

    To answer your last question:

    Yes, the master needs to know what slaves are out there and what their addresses are.  In a system, like a chemical plant, drawings of all instrumentation and controls (P&ID) provides names of all the devices.  Somewhere, there should be a table that matches these devices with unique addresses.  The master control station's software should be configured to know how to talk to all of these devices to get information about what is happening in the plant: such as pressures, temperature, flow, etc.  In general, for Modbus based systems, the control station's software is basically configured to poll pre-programmed list of registers and coils from a list of devices.  Perhaps once a second, or even slower.