Help with modbus addressing-Solved

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

viktor_au
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

Post by viktor_au »

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...
Attachments
NeedHelpWith_Addressing_1.jpg
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.

User avatar
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

Post by Benj »

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.

viktor_au
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

Post by viktor_au »

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.

User avatar
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

Post by Benj »

Hello,
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?
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.
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.
As long as both slave device have different slave addresses they can both have the same internal register and coil addresses.

User avatar
Steve001
Valued Contributor
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

Post by Steve001 »

Hi Victor

To add to bens post
When node N16 is connected, the node N15 goes into 'No Replay' mode.
are the addresses / settings correct ?

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
MSB-02 COMMS.JPG (101.43 KiB) Viewed 10876 times
Success always occurs in private and failure in full view.

viktor_au
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

Post by viktor_au »

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.

viktor_au
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

Post by viktor_au »

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.
Attachments
MasterFromNode15-1.jpg
MasterFromNode15-1.jpg (128.15 KiB) Viewed 10857 times

viktor_au
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

Post by viktor_au »

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)
Last edited by viktor_au on Wed Mar 06, 2019 10:03 pm, edited 2 times in total.

viktor_au
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

Post by viktor_au »

Steve: do you have multiple resistors fitted

I use this Max485 module. I think this module has build-in resistors.
Attachments
module_schematic.jpg
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.

viktor_au
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

Post by 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.
So far only the Node16 id address works, but not the register address and not the holding register data addresses.

User avatar
Steve001
Valued Contributor
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

Post by Steve001 »

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
Success always occurs in private and failure in full view.

User avatar
Steve001
Valued Contributor
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

Post by Steve001 »

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
Success always occurs in private and failure in full view.

User avatar
Steve001
Valued Contributor
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

Post by Steve001 »

[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
Success always occurs in private and failure in full view.

viktor_au
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

Post by viktor_au »

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?
Attachments
two_modules2-1.jpg
two_modules2-1.jpg (44.28 KiB) Viewed 10836 times

viktor_au
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

Post by viktor_au »

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.
Attachments
AddressesSetup-1.jpg
AddressesSetup-1.jpg (65.21 KiB) Viewed 10835 times

viktor_au
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

Post by viktor_au »

Testing Node16 as a stand alone node


Node16 sends the message back to Master with its own ID and with errors.
Attachments
Node16_addr3-2.jpg
Node16_addr3-2.jpg (122.12 KiB) Viewed 10833 times

viktor_au
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

Post by viktor_au »

Steve001 wrote: you can see that the same register is been read from different slave devices
Steve
I do not understand 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?

viktor_au
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

Post by viktor_au »

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.
UsingAddr40001.jpg
UsingAddr40001.jpg (130.5 KiB) Viewed 10820 times
Last edited by viktor_au on Thu Mar 07, 2019 4:14 am, edited 1 time in total.

viktor_au
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

Post by viktor_au »


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
StartAdrReg_Message.jpg (57.31 KiB) Viewed 10818 times

viktor_au
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

Post by viktor_au »

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
Attachments
Node15,Node16-OK.JPG
Node15,Node16-OK.JPG (189.95 KiB) Viewed 10807 times

User avatar
Steve001
Valued Contributor
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

Post by Steve001 »

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
Attachments
Capture.JPG
Capture.JPG (55.27 KiB) Viewed 10796 times
Success always occurs in private and failure in full view.

viktor_au
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

Post by viktor_au »

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?
Attachments
WeatherStationCables1.jpg
WeatherStationCables1.jpg (53.48 KiB) Viewed 10791 times

User avatar
Steve001
Valued Contributor
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

Post by Steve001 »

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
Success always occurs in private and failure in full view.

viktor_au
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

Post by viktor_au »

Thank you Steve.
All good.
Have to find more answers about the modbus addresses in relation to functions and nodes.

User avatar
Steve001
Valued Contributor
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

Post by Steve001 »

HI Viktor

Maybe this will help

https://www.schneider-electric.co.uk/en/faqs/FA168406/

Steve
Success always occurs in private and failure in full view.

Post Reply