I want to read MODBUS Register from an Energy Meter (Model : Elite 100 , Make : SECURE). But I unable to communicate to the Meter. in SERIAL MONITOR shows the faild to communicate and response code is "E2".
From your screenshot, you are using an Arduino MEGA2560 board. Here's your code modified to read 2 holding registers at address 40001 & 40002. I'm using serial #1 at 9600 baud for the Modbus comms to device #1.
Note that my RS485 module doesn't use separate RE & DE signals. Adjust the code accordingly.
// FOR MEGA2560 with Modbus device #1 on Serial #1 @ 9600 baud.
#include <ModbusMaster.h> //Library for using ModbusMaster
#define MAX485_REDE_PIN 5
#define MAX485_DE 2
#define MAX485_RE_NEG 3
ModbusMaster node; //object node for class ModbusMaster
void preTransmission() //Function for setting stste of Pins DE & RE of RS-485
{
// digitalWrite(MAX485_RE_NEG, 1);
// digitalWrite(MAX485_DE, 1);
digitalWrite(MAX485_REDE_PIN, 1);
}
void postTransmission()
{
// digitalWrite(MAX485_RE_NEG, 0);
// digitalWrite(MAX485_DE, 0);
digitalWrite(MAX485_REDE_PIN, 0);
}
void setup()
{
// pinMode(MAX485_RE_NEG, OUTPUT);
// pinMode(MAX485_DE, OUTPUT);
pinMode(MAX485_REDE_PIN, OUTPUT);
// digitalWrite(MAX485_RE_NEG, 0);
// digitalWrite(MAX485_DE, 0);
digitalWrite(MAX485_REDE_PIN, 0);
Serial.begin(9600); //Baud Rate as 9600
Serial.println( MAX485_REDE_PIN );
Serial1.begin(9600); //Baud Rate as 9600
node.begin(1, Serial1); //Slave ID as 1 on Serial #1
node.preTransmission(preTransmission); //Callback for configuring RS-485 Transreceiver correctly
node.postTransmission(postTransmission);
}
void loop()
{
uint8_t result = node.readHoldingRegisters(0x0000, 2); // Reads Holding Registers 40001 & 40002
Serial.println( result );
if (result == node.ku8MBSuccess)
{
Serial.print("data : ");
Serial.print(node.getResponseBuffer(0));
Serial.print(" ");
Serial.println(node.getResponseBuffer(1));
}
Serial.print("\n");
delay(3000);
}
I have a Modbus slave simulator setup with address 40001 holding the value 12, and address 40002 holding the value 34. My IDE serial monitor shows:
Thank you for your reply and support but still i'm facing problem and i'm unable to read holding register.
so basically I'm working on project which is about to read the holding register data (start from 40001 to 40006) which is comes from the potentiometer and want to print that data directly on serial monitor.
Here I'm attaching a connection diagram. One thing I also want to add that I'm bad at codding so, if possible please give some guidance and if possible give me the code regarding my project.
Firstly, I would suggest that you stay away from RX (0) and TX (1). They are used to communicate with the on-board USB-Serial adapter. Use RX1 (19) and TX1 (18) instead.
Secondly, how are you powering your MEGA2560 board? Are you powering it via the USB cable? If so, then I don't believe that there is any usable voltage on Vin. Use the 5V socket on your MEGA2560 to power your RS485 module (assuming it's one of the standard MAX485 based breakout boards).
i changed to RX1(19) and TX1(18) but it still getting error code 226.And the MAX485 module get power supply via arduino mega. and one more thing that arduino has separate power supply and ground as well and also connected to PC for serial monitor to watch data output. Now all the connections are as per your correction. and secondly i separate the connection of DE & RE.
A quick look at the user manual for that unit suggests that it supports a protocol called DCON as well as MODBUS with a software programmable baud rate. You need to figure out what the current comms settings are for your unit.
Appendix A on page 120 says that the module has an INIT mode where it can be set to known default settings.
Another thing I would recommend is to try and get hold of any manufacturer software that may be able to talk to the module. I did a bit of a search for you and discovered a program called DCON Utiltiy pro. The webpage says: "DCON Utility Pro is a toolkit that can help user easily to search, configure and test I/O modules". One of the images on that web page shows tM series modules and at the bottom of the web page it shows a table indicating support for the tM series modules.
If you can talk to your unit with the manufacturers software, then it (a) gives you confidence that you module is working, (b) tells you what protocol the module is configured for - hopefully MODBUS, (c) tells you the baud rate and (d) tells you the MODBUS address of the module.
You can then use your MEGA2560 as an RS485 MODBUS sniffer and print out the messages being transferred between the PC app and your module. That should confirm baud rate and module address. You should also be able to see the actual MODBUS message that reads the values you want.
You can then adjust your original MEGA2560 code accordingly and hopefully duplicate the MODBUS comms and talk to your module from the MEAG2560.