How can I request a Slave device to send me data, using Modbus communication blocks for Arduino in Simulink?

4 views (last 30 days)
I am using an Arduino Mega to communicate with a Thermostat device. The communication protocol is Modbus via RS485. I use my Arduino as Master and the ThermoStat as a Slave device. I know that I need to request the data first from my slave, using the master. I know the Slave address (254), Baud Rate (9,600), and that the information I need to read is a 16-bit integer at register adress 130 of the slave (which is a temperature). Does anybody have experience with the Arduino Modbus blocks to help me establish communication?

Answers (1)

Raj
Raj on 17 Apr 2024
As per your query, I am able to understand that you want to communicate between an Arduino as Master and ThermoStat as a Slave device using Modbus via RS485 as the communication protocol. MODBUS RTU RS485 serial communication protocol follows the client/server architecture. This is unlike the popular I2C serial communication protocol which follows master/slave architecture.
MATLAB provides various function blocks suck as Client Read, Client Write, Server Read, Server Write for Modbus protocol. For better understanding on how to configure your network and establish communication between Arduino and thermostat, you can refer to a similar example on MODBUS RS485 Communication Between Client and Server Using Arduino Board and adapt accordingly-
You can also refer to following documentation page on Modbus properties moving ahead with your peoject-
I hope this helps and you are able to proceed further!
  2 Comments
Christos Dimosthenous
Christos Dimosthenous on 17 Apr 2024
Good morning Raj and thank you for responding. Yes I have looked into all these and tried to experiment with the board and the thermostat, but nothing is working. I can't even get a Status enable back from my Master Read block. Baud rates are confirmed to be the same, RS485 pins are set properly (8 and 9), but it just doesn't seem to communicate at all. I set up the slave address on the thermostat, and then I check with the manufacturer's manual to identify the holding registers I want to read. I need to get two values from registers 131 and 345, but then I see that the block doesn't allow you to input anything over 255. Also even when I select to read multiple holding registers I still cannot input the values I wish. So even if I could communicate (which I can't) how do I read the specific registers? I guess that the sample time here corresponds to how often the Master asks the Slave to provide data, but nothing seems to be working. I cannot find any answers to these questions on the Mathworks documentation and I am really stuck!
Raj
Raj on 19 Apr 2024
Edited: Raj on 23 Apr 2024
I've also observed that we're unable to input register values greater than 255. It might be beneficial to reach out to MathWorks technical support for better assistance and to explore any possible workarounds.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!