Help with modbus addressing-Solved
Moderator: Benj
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Help with modbus addressing-Solved
Setup: Modbus master as Mega 2560
Two nodes: N15 and N16
FC8 checked for updates.
Problems:
When Master has one node N15 connected - OK.
When Master has two nodes connected N15 and N16 - problems.
When node N16 is connected, the node N15 goes into 'No Replay' mode.
Any help please?
PS
I tried to figure out the Modbus industrial settings with FC8 Modbus.
But...
Two nodes: N15 and N16
FC8 checked for updates.
Problems:
When Master has one node N15 connected - OK.
When Master has two nodes connected N15 and N16 - problems.
When node N16 is connected, the node N15 goes into 'No Replay' mode.
Any help please?
PS
I tried to figure out the Modbus industrial settings with FC8 Modbus.
But...
- Attachments
-
- NeedHelpWith_Addressing_1.jpg (127.02 KiB) Viewed 10933 times
Last edited by viktor_au on Thu Mar 07, 2019 4:13 am, edited 1 time in total.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Please help with modbus addressing
Hello,
With multiple slaves connected to a single master you need to use something like RS485 to allow the multiple devices to communicate back to the master without colliding with each other. RS485 converter modules are readily available and some of the newer ones feature automatic RX/TX switching so it's as easy as simply adding to your RX/TX signals.
Analogue inputs 30001 again start at 0 in Flowcode, just look at the Register address Hex range and that is the Flowcode address range.
With multiple slaves connected to a single master you need to use something like RS485 to allow the multiple devices to communicate back to the master without colliding with each other. RS485 converter modules are readily available and some of the newer ones feature automatic RX/TX switching so it's as easy as simply adding to your RX/TX signals.
Analogue inputs 30001 again start at 0 in Flowcode, just look at the Register address Hex range and that is the Flowcode address range.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
Thank you Ben
Re: RS485
Sure. I do use it.
Re: look at the Register address Hex range
Question1:
Does Master create some kind of a map of slaves/nodes addresses for itself?
And if it does, does this map should not exceed the slave's registers numbers?
Example
If Arduino Nano has 16 available 8 bit registers the Modbus Master would be able to use only 16 Nano Nodes?
Question 2:
Say, Master has request for Node15 to read the analogue input value by using the command:
ReadInputRegister(15,0x0F,2)
Where (15,0x0F,2): Node15, Start Address of register 15 for Atmega328p, Number of addresses.
Does it mean that I am not allowed to use that 0x0F address for other Nodes Master request?
Thank you.
Re: RS485
Sure. I do use it.
Re: look at the Register address Hex range
Question1:
Does Master create some kind of a map of slaves/nodes addresses for itself?
And if it does, does this map should not exceed the slave's registers numbers?
Example
If Arduino Nano has 16 available 8 bit registers the Modbus Master would be able to use only 16 Nano Nodes?
Question 2:
Say, Master has request for Node15 to read the analogue input value by using the command:
ReadInputRegister(15,0x0F,2)
Where (15,0x0F,2): Node15, Start Address of register 15 for Atmega328p, Number of addresses.
Does it mean that I am not allowed to use that 0x0F address for other Nodes Master request?
Thank you.
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Please help with modbus addressing
Hello,
No the Master has no map or clever storage. It just uses the Slave Address and then the coil/register address to access information on a slave.Does Master create some kind of a map of slaves/nodes addresses for itself? And if it does, does this map should not exceed the slave's registers numbers?
As long as both slave device have different slave addresses they can both have the same internal register and coil addresses.Say, Master has request for Node15 to read the analogue input value by using the command:
ReadInputRegister(15,0x0F,2)
Where (15,0x0F,2): Node15, Start Address of register 15 for Atmega328p, Number of addresses.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
Re: Please help with modbus addressing
Hi Victor
To add to bens post
have you tried reading N15 & N16 on there own
do you have a wiring error (A & B crossed)
have you got the termination resistor installed
do you have multiple resistors fitted
how long are you waiting for the reply from N15 before sending a request to N16 ? we used 500ms at work
if you look at the attached -
you can see that the same register is been read from different slave devices
red - send
blue - receive
Steve
To add to bens post
are the addresses / settings correct ?When node N16 is connected, the node N15 goes into 'No Replay' mode.
have you tried reading N15 & N16 on there own
do you have a wiring error (A & B crossed)
have you got the termination resistor installed
do you have multiple resistors fitted
how long are you waiting for the reply from N15 before sending a request to N16 ? we used 500ms at work
if you look at the attached -
you can see that the same register is been read from different slave devices
red - send
blue - receive
Steve
- Attachments
-
- MSB-02 COMMS.JPG (101.43 KiB) Viewed 10876 times
Success always occurs in private and failure in full view.
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
Thank you Ben and Steve
I will answer all questions a bit later.
I thing right now I have to backup a bit and try to understand more the modbus system.
For example, in Node1 I have to read three values: temperature, humidity and barometer.
Do I have to create in Master for Node1 three requests:
Rx=ModbusMaster1::ReadHoldingRegister(node_id,0,1)
Rx=ModbusMaster1::ReadHoldingRegister(node_id,1,1)
Rx=ModbusMaster1::ReadHoldingRegister(node_id,2,1)
And only one if Rx=0 branch.
Example:
if Rx=0
tempbyte1=ModbusMaster1::GetResponse(byte4) //Get Temperature byte1
tempbyte2=ModbusMaster1::GetResponse(byte4) //Get Temperature byte2
humid1=ModbusMaster1::GetResponse(byte5) //Get Humidity byte1
humid2=ModbusMaster1::GetResponse(byte6) //Get Humidity byte2
bar1=ModbusMaster1::GetResponse(byte7) //Get Barometer byte1
bar2=ModbusMaster1::GetResponse(byte8) //Get Barometer byte2
--------------------------------------------------------------------------------
I think I am doing something wrong in the code, as the hardware and FC8 component work OK.
I will answer all questions a bit later.
I thing right now I have to backup a bit and try to understand more the modbus system.
For example, in Node1 I have to read three values: temperature, humidity and barometer.
Do I have to create in Master for Node1 three requests:
Rx=ModbusMaster1::ReadHoldingRegister(node_id,0,1)
Rx=ModbusMaster1::ReadHoldingRegister(node_id,1,1)
Rx=ModbusMaster1::ReadHoldingRegister(node_id,2,1)
And only one if Rx=0 branch.
Example:
if Rx=0
tempbyte1=ModbusMaster1::GetResponse(byte4) //Get Temperature byte1
tempbyte2=ModbusMaster1::GetResponse(byte4) //Get Temperature byte2
humid1=ModbusMaster1::GetResponse(byte5) //Get Humidity byte1
humid2=ModbusMaster1::GetResponse(byte6) //Get Humidity byte2
bar1=ModbusMaster1::GetResponse(byte7) //Get Barometer byte1
bar2=ModbusMaster1::GetResponse(byte8) //Get Barometer byte2
--------------------------------------------------------------------------------
I think I am doing something wrong in the code, as the hardware and FC8 component work OK.
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
Re: have you tried reading N15 & N16 on there own
I have changed the code and tried the Node15 first with Master:
Master Request
Rx=ModbusMaster1::ReadHoldingRegister(node_id,0,3)
Node15 with the next setup:
ModbusSlave1::SetHoldingRegister(0,.int)
ModbusSlave1::SetHoldingRegister(1,.int)
ModbusSlave1::SetHoldingRegister(2,21)
This setup works for Node15. I have all three integers as Data1, Data2, Data3.
Does it mean I used three addresses as well? 40001,40002,4003?
My problem is to figure out the address for Node16.
I thought that if I used address 0 (40001) for Node15, than I have to use the address 1(40002) for Node16. It did not work.
I tried the addresses 2, 3, 4 in Master Request and in Node16 Slave/Node properties. But then I do not know what is the address for the command to read the holding register as well as how many registers I have to write in Slave/Node properties.
I have changed the code and tried the Node15 first with Master:
Master Request
Rx=ModbusMaster1::ReadHoldingRegister(node_id,0,3)
Node15 with the next setup:
ModbusSlave1::SetHoldingRegister(0,.int)
ModbusSlave1::SetHoldingRegister(1,.int)
ModbusSlave1::SetHoldingRegister(2,21)
This setup works for Node15. I have all three integers as Data1, Data2, Data3.
Does it mean I used three addresses as well? 40001,40002,4003?
My problem is to figure out the address for Node16.
I thought that if I used address 0 (40001) for Node15, than I have to use the address 1(40002) for Node16. It did not work.
I tried the addresses 2, 3, 4 in Master Request and in Node16 Slave/Node properties. But then I do not know what is the address for the command to read the holding register as well as how many registers I have to write in Slave/Node properties.
- Attachments
-
- MasterFromNode15-1.jpg (128.15 KiB) Viewed 10857 times
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
Ben: It just uses the Slave Address and then the coil/register address to access information on a slave.
That is the problem for me (or one of the problems) as I do not know what Node16 register address should be. 4002? As the Node15 used 4001?
As for coil/register address:
I think I read somewhere on this forum that I have to assign the coil/register address on Node16 to 0 (if I use only one coil/register)
That is the problem for me (or one of the problems) as I do not know what Node16 register address should be. 4002? As the Node15 used 4001?
As for coil/register address:
I think I read somewhere on this forum that I have to assign the coil/register address on Node16 to 0 (if I use only one coil/register)
Last edited by viktor_au on Wed Mar 06, 2019 10:03 pm, edited 2 times in total.
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
Steve: do you have multiple resistors fitted
I use this Max485 module. I think this module has build-in resistors.
I use this Max485 module. I think this module has build-in resistors.
- Attachments
-
- module_schematic.jpg (62.85 KiB) Viewed 10847 times
Last edited by viktor_au on Wed Mar 06, 2019 10:19 pm, edited 1 time in total.
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
Steve: have you tried reading N15 & N16 on there own
Node 16 works alone fine. Master reads Node16, if the register address = 0 (40001).
However if I use Node15 with register address = 0 (40001) than Node16 accepts the message and returns the message to Master, but the data is wrong.
So far only the Node16 id address works, but not the register address and not the holding register data addresses.
Node 16 works alone fine. Master reads Node16, if the register address = 0 (40001).
However if I use Node15 with register address = 0 (40001) than Node16 accepts the message and returns the message to Master, but the data is wrong.
So far only the Node16 id address works, but not the register address and not the holding register data addresses.
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
Re: Please help with modbus addressing
Hi Victor
The Modbus slave(s) - can be many devices connected to the loop
these have holding registers 40001,40002,4003
for example
40001 Temperature
40002 Humidity
40003 Barometer
they also have an address 1 - 255
the master sends a request message to read a register from a slave device
slave addr : function code : address : data : crc
the master doesn't care that node 15, and 16 have the same registers, you tell the master
read holding register (3), address (slave ID No), data, crc (remember it takes time for the slave to respond 250msec rings a bell but not sure where from)
the message is sent to all connected devices on the loop and slave 15 responds to the message by sending the reply for the query to read the register
hope this helps
Steve
The Modbus slave(s) - can be many devices connected to the loop
these have holding registers 40001,40002,4003
for example
40001 Temperature
40002 Humidity
40003 Barometer
they also have an address 1 - 255
the master sends a request message to read a register from a slave device
slave addr : function code : address : data : crc
the master doesn't care that node 15, and 16 have the same registers, you tell the master
read holding register (3), address (slave ID No), data, crc (remember it takes time for the slave to respond 250msec rings a bell but not sure where from)
the message is sent to all connected devices on the loop and slave 15 responds to the message by sending the reply for the query to read the register
hope this helps
Steve
Success always occurs in private and failure in full view.
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
Re: Please help with modbus addressing
Hi Victor
if you are using this board for each slave then you will have two termination resistors fitted (R7)
can you remove one of them (or both and fit one externally ) ?
Steve
if you are using this board for each slave then you will have two termination resistors fitted (R7)
can you remove one of them (or both and fit one externally ) ?
Steve
Success always occurs in private and failure in full view.
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
Re: Please help with modbus addressing
[quote="viktor_au"]Steve: have you tried reading N15 & N16 on there own
Node 16 works alone fine. Master reads Node16, if the register address = 0 (40001).
However if I use Node15 with register address = 0 (40001) than Node16 accepts the message and returns the message to Master, but the data is wrong. quote]
sounds like they both have the same address
Node 16 works alone fine. Master reads Node16, if the register address = 0 (40001).
However if I use Node15 with register address = 0 (40001) than Node16 accepts the message and returns the message to Master, but the data is wrong. quote]
sounds like they both have the same address
Success always occurs in private and failure in full view.
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
Resistors
OK, will remove and leave only one on the 2nd module.
Steve: for example
40001 Temperature
40002 Humidity
40003 Barometer
I cannot understand.
Master uses only one request:
Rx=ModbusMaster1::ReadHoldingRegister(node_id,0,3)
Where after node_id goes number 0, and number 0 = 40001.
Where from 40002 for Humidity comes from?
Where from 40003 for Barometer comes from?
OK, will remove and leave only one on the 2nd module.
Steve: for example
40001 Temperature
40002 Humidity
40003 Barometer
I cannot understand.
Master uses only one request:
Rx=ModbusMaster1::ReadHoldingRegister(node_id,0,3)
Where after node_id goes number 0, and number 0 = 40001.
Where from 40002 for Humidity comes from?
Where from 40003 for Barometer comes from?
- Attachments
-
- two_modules2-1.jpg (44.28 KiB) Viewed 10836 times
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
Steve: sounds like they both have the same address
Steve, I have used an example of testing the Node16 with Modbus Address = 0 (40001) without Node15 just to see if it works.
However the problem is to test Node16 with different Modbus address, say - 3 (40004).
Should Node16 work alone with this address even if Node is 15 switched off?
For some reason I cannot do that.
Steve, I have used an example of testing the Node16 with Modbus Address = 0 (40001) without Node15 just to see if it works.
However the problem is to test Node16 with different Modbus address, say - 3 (40004).
Should Node16 work alone with this address even if Node is 15 switched off?
For some reason I cannot do that.
- Attachments
-
- AddressesSetup-1.jpg (65.21 KiB) Viewed 10835 times
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
Testing Node16 as a stand alone node
Node16 sends the message back to Master with its own ID and with errors.
Node16 sends the message back to Master with its own ID and with errors.
- Attachments
-
- Node16_addr3-2.jpg (122.12 KiB) Viewed 10833 times
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
I do not understand Steve.Steve001 wrote: you can see that the same register is been read from different slave devices
Steve
'Same register' - what is it?
It is a register name or is it a register address in slave?
I do not follow.
I thought that Master can request data only from one slave/node with only one assigned register address.
Say, if Master uses the address of 40001 (command in FC8 Modbus Master - ReadHoldingRegister(node_id,0,1) than this address 40001 can be used only for this slave/node and not for other nodes. Is it correct?
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
Benj wrote: As long as both slave device have different slave addresses they can both have the same internal register and coil addresses.
This is the solution. The key answer.
Steve said a bit differently and I couldn't understand him first, when he wrote:
viktor_au wrote:you can see that the same register is been read from different slave devices
As I managed to damage one Nano board, I checked the Node16 first, as I couldn't make it work.
After I changed the settings (as on photo below) the Node16 begun to work.
Last edited by viktor_au on Thu Mar 07, 2019 4:14 am, edited 1 time in total.
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Please help with modbus addressing
What is the reason I tried to assign the Node/Slave internal address to a different one?
The Modbus Slave/Node as a component has the property under Modbus Registers - > Starting address.
On the photo you can see the pop-up message (if you hover above the text 'Starting address")
For some reason I believed, that if Node15 internal 'Starting address' is set to 0 and Node15 has three readings of the holding registers,
we have three different operations with different internal registers.
As a result, I thought, Node16 internal 'Starting address' must not start as 0 or 1 or 2, but only as 3, as the pop-up message suggest to do.
Probably I am missing something in this pop-up message, but without Ben's and Steve's help I wouldn't be able to solve this problem.
Thank you Ben and Steve!
- Attachments
-
- StartAdrReg_Message.jpg (57.31 KiB) Viewed 10818 times
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Help with modbus addressing-Solved
Final test with Mega2560 as Modbus Master, Nano as Node16 and Uno as Node15.
All good.
Would be good as well if somebody explain to forum users what is the reason to use the same Modbus Register Address ( for example- 40001 (0)) to request the data from a few nodes?
Is it normal?
Why do not use one Modbus Register Address for one Node?
Thanks
All good.
Would be good as well if somebody explain to forum users what is the reason to use the same Modbus Register Address ( for example- 40001 (0)) to request the data from a few nodes?
Is it normal?
Why do not use one Modbus Register Address for one Node?
Thanks
- Attachments
-
- Node15,Node16-OK.JPG (189.95 KiB) Viewed 10807 times
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
Re: Help with modbus addressing-Solved
Hi Victor
Glad it working for you now.
Noticed that your loop is wired incorrect though (unless it's how you have drawn it)
see attached
Steve
Glad it working for you now.
Noticed that your loop is wired incorrect though (unless it's how you have drawn it)
see attached
Steve
- Attachments
-
- Capture.JPG (55.27 KiB) Viewed 10796 times
Success always occurs in private and failure in full view.
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Help with modbus addressing-Solved
Noise is a very important issue, is not it?
You have raise this point when I was thinking about the cable design.
I made/draw some draft version of the Weather Station wiring.
As the Master would be inside the house and all nodes up in the mast - I have to connect them by the diagram in the photo. I will remove all the R17 120oHm resistors except two on the both ends.
However I see some problems.
Most of the nodes on the mast would be next to each other. Which one I have to make the end one? Probably the top one.
I do not think it will be some kind of star connection as I could sandwich one node on the top of the other and I can make some vertical 'ladder' system.
What do you think?
You have raise this point when I was thinking about the cable design.
I made/draw some draft version of the Weather Station wiring.
As the Master would be inside the house and all nodes up in the mast - I have to connect them by the diagram in the photo. I will remove all the R17 120oHm resistors except two on the both ends.
However I see some problems.
Most of the nodes on the mast would be next to each other. Which one I have to make the end one? Probably the top one.
I do not think it will be some kind of star connection as I could sandwich one node on the top of the other and I can make some vertical 'ladder' system.
What do you think?
- Attachments
-
- WeatherStationCables1.jpg (53.48 KiB) Viewed 10791 times
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact:
Re: Help with modbus addressing-Solved
Hi Viktor
Modbus is perfectly at home in an electrically noisy environment
I would loop in and out of each slave (maybe start at the top) depends if you going to add more sensors and which end you will add them.
Start configurations don't work very well and may not even work at all
if you wire at the schematic in the above post with a 2 core screen cable - you should have next to no problems at all
Steve
Modbus is perfectly at home in an electrically noisy environment
I would loop in and out of each slave (maybe start at the top) depends if you going to add more sensors and which end you will add them.
Start configurations don't work very well and may not even work at all
if you wire at the schematic in the above post with a 2 core screen cable - you should have next to no problems at all
Steve
Success always occurs in private and failure in full view.
-
- Posts: 342
- Joined: Fri Jan 26, 2018 12:30 pm
- Location: South Australia
- Has thanked: 44 times
- Been thanked: 60 times
- Contact:
Re: Help with modbus addressing-Solved
Thank you Steve.
All good.
Have to find more answers about the modbus addresses in relation to functions and nodes.
All good.
Have to find more answers about the modbus addresses in relation to functions and nodes.
- Steve001
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
- Contact: