Error In reading Holding Register of EM6400NG Energy Meter with Rs485 & Modbus

I am writing a Arduino program to get data from Schneider EM6400NG by using Arduino MEGA 2560. Arduino is Master, device is slave.

Aim :- To read holding register of EM6400NG energy meter, and Collect energy parameter from device

here in used : ModbusMaster library

EM6400NG register address Link :-

Problem:- When I run code in IDE Arduino, and print Result Value monitor display error 226 - in below code i have removed all seril print

Then I remove Arduino and just use RS485.

  • When I use Modscan software. I can completely read data from device

Is there something wrong with the request signal? Am I making any mistakes in the circuit or the code?

i checked my rs485 ti ttl module using arduino to pc data communication its work fine, whats wrong in program or anything other

please help me for this, all the details : circuit diagram, Arduino code and received output attached, PFA

Code for read Holding register

// ****** DEFINES ******
#define MAX485_DE      3
#define MAX485_RE_NEG  2


// ****** INCLUDES ******
#include <ModbusMaster.h>


// ****** GLOBALS ******
ModbusMaster node;  // instantiate ModbusMaster object
float reg1;     // will store the float value found at 3910/3911
float reg2;     // will store the float value found at 3914/3915
int low_word;   // this will hold the low 16-bit resgter value after a read
int high_word;  // this will hold the high 16-bit resgter value after a read

// converting to floating point - union structure
union u_tag {
  int bdata[2];
  float flotvalue;
} uniflot;


// ****** Transmission Functions ******
void preTransmission()
{
  digitalWrite(MAX485_RE_NEG, 1);
  digitalWrite(MAX485_DE, 1);
  Serial.println("preTransmission");
}

void postTransmission()
{
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);
  Serial.println("postTransmission");
}


// ****** STANDARD ARDUINO SETUP FUNCTION ******
void setup() {
  
  // make pins 2 and 3 output pins for Max485 flow control
  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);

  // Init in receive mode
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

 Serial.begin(9600);     // TX0/RX0 serial monitor
  Serial1.begin(9600,SERIAL_8N1);   // TX1/RX1 Modbus comms

  // Modbus slave ID = 1
  node.begin(1, Serial1);

  // Callbacks allow us to configure the RS485 transceiver correctly
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);


}

// ****** STANDARD ARDUINO LOOP FUNCTION ******
void loop() {

  uint8_t result;
  // Read Line to Neutral Voltage
  result = node.readHoldingRegisters(0x3028, 2);
 
  //result = node.readHoldingRegisters(1, 2);
   if (result == node.ku8MBSuccess) 
  {

    high_word = node.getResponseBuffer(0x00);
    low_word = node.getResponseBuffer(0x01);
    
    uniflot.bdata[1] = low_word;    // Modbus data 8-bit low word
    uniflot.bdata[0] = high_word;   // Modbus data 8-bit high word

    reg1 = uniflot.flotvalue;
    
    Serial.print("Line to Neutral Voltage: ");
    Serial.println(reg1);
    
  } 
//  node.clearResponseBuffer();
  delay(500);   // small delay between reads
  
  //Read Frequency
  result = node.readHoldingRegisters(3110, 2);
 
  if (result == node.ku8MBSuccess)
  {
    high_word = node.getResponseBuffer(0x00);
    low_word = node.getResponseBuffer(0x01);
    
    uniflot.bdata[1] = low_word;    // Modbus data 8-bit low word
    uniflot.bdata[0] = high_word;   // Modbus data 8-bit high word

    reg2 = uniflot.flotvalue;
    
    Serial.print("Frequency: ");
    Serial.println(reg2);
  }

  delay(1000);    // repeat reading every 2 seconds
  node.clearResponseBuffer();
  
}

EM6400.ino (2.78 KB)

When I run code in IDE Arduino, and print Result Value monitor display error 226 - in below code i have removed all seril print

226 = E2 means response timeout, so the opposite party didn't send a reply message.

Serial1.begin(9600,SERIAL_8N1);   // TX1/RX1 Modbus comms

but the Schneider documentation says:

The meteris factory-configuredwith the following default serial communications settings:

  • Protocol= ModbusRTU
  • Address= 1
  • Baudrate = 19200
  • Parity= Even

So the option should be SERIAL_8E1.

Did you check the configured slave ID? Is it actually 1 as you set in your code?

yes, i have checked all the parameter i have changed the baud rate from 19200 to 9600

and have set parity as none also tried with even and odd parity all worked easily with by mod scan software, i read the all forum post and correct itself ,

but till data is not able to received.

yes, i have checked all the parameter i have changed the baud rate from 19200 to 9600

and have set parity as none also tried with even and odd parity all worked easily with by mod scan software, i read the all forum post and correct itself ,

What else did you change? Don't you think you should tell us which values you change from the default in the configuration?

#define MAX485_DE      3
#define MAX485_RE_NEG  2

This doesn't match the wiring diagram!

pylon:
What else did you change? Don't you think you should tell us which values you change from the default in the configuration?

#define MAX485_DE      3

#define MAX485_RE_NEG  2




This doesn't match the wiring diagram!

Can you please tell me what I'm doing wrong here, please help

If some things wrong in code or anather way for get data, I'm trying from long time but not able,

Which register are you trying to read?

I'm going to guess that you are trying to read the "Voltage A-N" register.

Secondly I'm going to hazard a guess that the Excel spreadsheet is saying that the data is held in 4 bytes as it says the data type is a FLOAT32 occupying 2 INT16's.

I would use your Modscan software to talk to the device so you can establish the correct serial port parameters (baud rate, parity etc) as the user manual indicates that these can be changed.

Once you know the correct serial parameters, I think you need to modify your code so that the line:

result = node.readHoldingRegisters(0x3028, 2);

reads:

result = node.readHoldingRegisters(3028, 4);

The reason being that the registers appear to be specified in decimal, NOT hexadecimal. And you need to ask for 4 bytes instead of 2.

Can you please tell me what I'm doing wrong here, please help

In the wiring diagram it's the other way around.

The reason being that the registers appear to be specified in decimal, NOT hexadecimal. And you need to ask for 4 bytes instead of 2.

Wrong, the readHoldingRegisters() method takes the number of registers to read, not the number of bytes.

Ah, ok, so what the OP should try is:

result = node.readHoldingRegisters(3028, 2); to read 2x 16-bit registers to get the 32-bit "FLOAT32" value.

markd833:
Ah, ok, so what the OP should try is:

result = node.readHoldingRegisters(3028, 2); to read 2x 16-bit registers to get the 32-bit "FLOAT32" value.

Yes, but as long as he still get timeouts the reading of the correct register isn't that important. He cannot communicate with the device yet, so first he has to fix that.

markd833:
Which register are you trying to read?

I'm going to guess that you are trying to read the "Voltage A-N" register.

Secondly I'm going to hazard a guess that the Excel spreadsheet is saying that the data is held in 4 bytes as it says the data type is a FLOAT32 occupying 2 INT16's.

I would use your Modscan software to talk to the device so you can establish the correct serial port parameters (baud rate, parity etc) as the user manual indicates that these can be changed.

Once you know the correct serial parameters, I think you need to modify your code so that the line:

result = node.readHoldingRegisters(0x3028, 2);

reads:

result = node.readHoldingRegisters(3028, 4);

The reason being that the registers appear to be specified in decimal, NOT hexadecimal. And you need to ask for 4 bytes instead of 2.

Thank you sir, for the information when I read data in Modscan Software here shows for single parameters taking 2byte hence I entered there 2byte

Please Check attached modscan Software output. Its taking 2 byte for A-n voltage 3028 & 3029.

Please correct me if

modscam output :- WhatsApp Image 2020-08-31 at 2.43.54 PM.jpeg - Google Drive

modscam output :- WhatsApp Image 2020-08-31 at 2.43.54 PM.jpeg - Google Drive

No Google drive URLs. Post the output to this forum!