Modbus slave RS485

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Modbus slave RS485

Post by Lord Grezington »

Hello Everyone

I have run a Modbus RS485 slave program a while back, and in general seems to work OK but I have found some problems (perhaps bugs) that I need resolved if possible.

1 - When I change the baud rate to below 9600 the communication breaks down. Works fine with all other baud rates I have tested.
2 - When I read multiple registers (in my case 10, from register 1 - 11) it reads OK, but then communication breaks down. If I read a lower number of registers or one register at a time, I dont seem to get any problems.
3 - I have not been able to test this, but I have been told that the communication breaks down when attached to a high traffic flow bus

I am happy to do any further testing if you need more information

Thanks

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: Modbus slave RS485

Post by Benj »

Hello,
1 - When I change the baud rate to below 9600 the communication breaks down. Works fine with all other baud rates I have tested.
This will largely depend on the micro your using and the speed the micro is running at. Typically the faster the micro is the harder it is to generate the slower baud rates. However let me know your current setup and I'll investigate the code is being generated correctly.
2 - When I read multiple registers (in my case 10, from register 1 - 11) it reads OK, but then communication breaks down. If I read a lower number of registers or one register at a time, I dont seem to get any problems.
Not sure what might be causing this at the specific count of 10 registers. I'll investigate. Does the same happen if you try and read more than 10?
3 - I have not been able to test this, but I have been told that the communication breaks down when attached to a high traffic flow bus
I'm assuming this is in a multi master type situation. As the bus gets busy the chance of a master interrupting another master's communications increases. Care should be taken to try and avoid collisions by first checking the bus is not in use and if busy having random wait delays before trying again. You may also need to manually resend messages until you get a correct acknowledge. Again beware as if multiple masters are performing retries then you could get collisions again and again. The random delay would be useful here too. Multi master systems are generally fairly complicated to get right and ideally should be avoided if possible.

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Hi
I am new to this forum, I don't know how to post a question in this forum. Anybody please advise me which PIC and RS485 hardware is successfully working with Modbus RTU Slave component.

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: Modbus slave RS485

Post by Benj »

Hello,

The idea is that it will work with everything,

Ideally the MCU should have a hardware UART and enough memory to perform the Modbus routines and store the various register values.

As for the RS485 hardware again most RS485 line drivers will conform to a standard and should work fine.

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Thanks
I will try to download trial version and try it.
Regards,
Raja

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Hi
I tried the Modbus slave component which is working well in simulation, perfectly communicating with my application. But it is not working with real hardware, I used PIC18F2550 with 20MHz crystal and tried two types of readymade RS485 boards as in attached images. When I tried Modbus master with the same hardware it is working fine.
May I have any help for this problem.
Attachments
RS485_2.png
(297.58 KiB) Downloaded 2711 times
RS485_1.png
(557.15 KiB) Downloaded 2711 times

Lord Grezington
Flowcode V4 User
Posts: 288
Joined: Wed Nov 02, 2011 11:15 pm
Has thanked: 29 times
Been thanked: 30 times
Contact:

Re: Modbus slave RS485

Post by Lord Grezington »

Hi Ben, sorry its taken so long to respond:
This will largely depend on the micro your using and the speed the micro is running at. Typically the faster the micro is the harder it is to generate the slower baud rates. However, let me know your current setup and I'll investigate the code is being generated correctly.
I am using a dsPIC33EP32MC504 running 120Mhz running only the Modbus Slave component.
Not sure what might be causing this at the specific count of 10 registers. I'll investigate. Does the same happen if you try and read more than 10?
Yes, 10 or more registers
I'm assuming this is in a multi master type situation.
No, I think in this application they have an HMI as the master, however they also have a PLC on the bus being run as a slave.

@Raja

Using cheap breakout boards could be the problem, we designed our own hardware around the SN75HVD12P and it has worked flawlessly (unless my current issues are related). We have also used it in other RS485 applications with lower clock frequencies (64Mhz with the 18F25K22). All you need to do is ensure you have the basics (Ensure the correct Power Supply, check correct connections on A & B, and make sure the termination resistor is fitted if you’re on the end node).

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Hi
Why I am wondering the same hardware is working normal with Modbus Master component, I can communicate with a 3rd party temperature controller without any hassles. Master is working good even with in house made RS485 board (with 74HC04 and SN75176 for automatic read/write control) by selecting RS232 protocol in the program. COM settings are; RTU, 9600,8,N,1. These same things are not working with slave component.

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Modbus slave RS485

Post by AbhijitR »

Hello! v.rajaji

I have used the Modbus Slave component in one of my projects and it worked absolutely well, I have attached the picture of the properties of the Slave component which I used, I hope this shall help. I used PIC16F1938 with internal clock at 4MHz.

I used ModScan32 on my desktop computer as master to communicate with the slave hardware and also one industrial HMI as master, in both cases it worked good.

Thank you.

Regards
Abhi
Attachments
MB_Slave_Properties.PNG
(129.76 KiB) Downloaded 2665 times

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Hi Abhijith

Thanks for help. can you please check my program to confirm whether I am making any mistake. I need to read/write holding registers rather than coils.
Attachments
MBTEST.fcfx
(16.39 KiB) Downloaded 224 times

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Hi Abhijit

I tried the settings as per yours but no luck. Please check if my coding is correct or not.

Regards,
Raja

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Hi
Example Modbus slave programs are with Read/Write coils only, anybody can share a working Modbus slave program with holding registers.

Regards,
Raja

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Modbus slave RS485

Post by AbhijitR »

Hello! Raja

I have made few changes in your flowchart, I have added one push button to show the digital input, one output as digital output, one analog input and one holding register from your chart, unfortunately I was not able to test It, as I am not on my workbench for the moment, it complied well without errors.

Do update, thank you.

Regards
Abhi
Attachments
MBTEST_10-10-2019.fcfx
(18.4 KiB) Downloaded 171 times

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Hi Abhijit

Thanks for help. I tried revised program but no luck from my end, my RS485 board receiving data from the PC but no response from PIC. When you have time please check it with your hardware and let me know.

Regards,
Raja

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Hi Abhijit
Now I found it working with same hardware and same sample program which I uploaded. All it was happened by changing the Baud rate in master device.
In flowcode program the Baud rate is 9600 which is not at all communicating with the master device, I changed baud rate to 2400 in the master device and found it is working fine. Can anyone support me for this issue.

Regards,
Raja

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Hi Abhijit

Finally it worked out for me, the baud rate issue is due to chip configuration settings. By changing CPU system clock select to OSC/1 and OSC select to Divided by 5 (20MHz input). Now I will look into remaining programming stuff.
Thanks for your support.

Regards,
Raja

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Modbus slave RS485

Post by AbhijitR »

Hello! Raja

Ah! Finally everything worked as you wanted, I am happy to know that and more than happy to know that I could help.

All the best for the remaining coding, cheers...

Regards
Abhijit

v.rajaji
Posts: 12
Joined: Wed Sep 18, 2019 9:46 am
Been thanked: 1 time
Contact:

Re: Modbus slave RS485

Post by v.rajaji »

Hi Abhijit

Can you please share your RS485 breakout board schematic or photo for my reference. I am uploading a circuit is it same as yours.

regards,
Raja
Attachments
MAX485-Module-Schematic.jpg
MAX485-Module-Schematic.jpg (159.36 KiB) Viewed 7968 times

User avatar
AbhijitR
Posts: 298
Joined: Fri Nov 07, 2014 12:48 pm
Location: Pune, India
Has thanked: 279 times
Been thanked: 78 times
Contact:

Re: Modbus slave RS485

Post by AbhijitR »

Hi! Raja

Below is the link from where I purchased one for my project.

https://www.amazon.in/gp/product/B016F6 ... UTF8&psc=1

Regards
Abhi

Post Reply