1

I was trying to extract data from a multi-function meter with RS485 connectivity and I am using Arduino as master, Arduino Uno and multi-function meter are connected via MAX485 module.

I have tried some code but it returns an E2 error which means communication error.

Kindly explain me the program and help me to solve it.

#include <ModbusMaster.h>

#define MAX485_DE 3 #define MAX485_RE_NEG 2 ModbusMaster node;

void preTransmission() { digitalWrite(MAX485_RE_NEG,1); digitalWrite(MAX485_DE,1); }

void postTransmission() { digitalWrite(MAX485_RE_NEG,0); digitalWrite(MAX485_DE,0); }

void setup() { pinMode(MAX485_RE_NEG,OUTPUT); pinMode(MAX485_DE,OUTPUT); digitalWrite(MAX485_RE_NEG,0); digitalWrite(MAX485_DE,0);

Serial.begin(9600);

node.begin(1,Serial); node.preTransmission(preTransmission); node.postTransmission(postTransmission); }

void loop() { uint8_t resultMain;

resultMain = node.readHoldingRegisters(0x0100,6); Serial.print(resultMain,HEX);

if (resultMain == node.ku8MBSuccess) { Serial.print(resultMain); Serial.print(node.getResponseBuffer(0x32)); } delay(1000); }

ocrdu
  • 1,775
  • 3
  • 11
  • 24
  • Can you please let us know the energy meter which you are using? – Maaz Sk Dec 29 '20 at 05:13
  • 1
    secure ELITE 300 – hrishi akash Dec 29 '20 at 05:19
  • Can you please use software serial for the communication between meter and arduino because your uart can't be shared simultaneously with both the PC and the meter. That could be the reason why it shows you Communication fail error – Maaz Sk Dec 29 '20 at 06:12
  • can you pls send me the example code becaus i have tried that also but ir shing the same error – hrishi akash Dec 29 '20 at 06:34
  • "means communication error". More specifically a timeout. – timemage Dec 29 '20 at 14:53
  • You have node.begin(1,Serial); where 1 appears to be the modbus slave ID. Is that in fact the ID of your meter? – timemage Dec 29 '20 at 15:14
  • 1
    yes that's the slave id – hrishi akash Dec 29 '20 at 16:26
  • See whether or not it makes any difference with your A and B signals swapped. – timemage Dec 29 '20 at 22:31
  • ya i tried that also but same error my register no is 40100 it is an holding register and its length is 32 bit its hexa value is 0064 i am i making mistake in this anywhere ? – hrishi akash Dec 30 '20 at 03:10
  • First, use another Serial port for the RS485; if you have an Arduino Mega, you can just use that instead to minimize code changes since it has multiple hardware UARTs. You'll only need to change node.begin(1, Serial) to something like node.begin(1, Serial2). Next, make sure your hardware connections are correct; in addition to the 2 RS485 connections (A and B), there MUST also be a common GND connection between your Arduino and the meter. Verify your connections by using the RS485 connection to send data between 2 Arduinos, without the Modbus layer. Just send strings back and forth. – SoreDakeNoKoto Dec 30 '20 at 09:40

0 Answers0