1 year ago
#231340
Rover_bot
Read data from Elite 100 energy meter using RS 485 MODBUS with ARduino mega
I'm trying to read 4 Registers from a Energy Meter (Model no: ELITE 100, Make : SECURE), using Arduino Mega. I'm using RS 485 to TTL module for arduino to communicate with the Energy meter. After uploading the code,in serial monitor I saw that arduino fails to communicate with the energy meter, and show the response code in hex format is "E2". I unable to understand what is the actual problem. Please help me.
Energy Meter MODBUS Register link: https://drive.google.com/drive/folders/1kTQg0wvcX-iG7jkeZHwIUkK8e-9VVVW_?usp=sharing
Some settings values are: Parity Bit: None, Baud Rate : 9600 , Stop Bit : 1
CODE Output is: Failed, Response Code: E2
#include<ModbusMaster.h>
/* DI = UNO / NANO TX PIN / arduino mega pin 1 TX pin
RO = UNO/ NANO RX PIN / arduino mega pin 0 RX Pin
*/
#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);
// Init in receive mode
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
Serial.begin(9600, SERIAL_8N1);
//slave ID 1
node.begin(1, Serial);
Serial.println("Starting Modbus Transaction:");
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
uint16_t newData = 0;
float floatData;
double dataOne;
void loop() { // loop starts from here.
static uint32_t i;
uint8_t j, result;
uint16_t data[10];
i++;
result = node.readHoldingRegisters(40172, 2); // read holding registars
Serial.println(" ");
/*
if (result == node.ku8MBSuccess) {
Serial.print("\nSuccess, Received data 0: ");
for (j = 0; j < 2; j++) { // THIS FUNCTION READ SINGLE REGISTAR
data[j] = node.getResponseBuffer(j);
floatData, dataOne = node.getResponseBuffer(j);
Serial.print("\nHex data:");
Serial.print(data[j], HEX);
Serial.print(" ");
Serial.print("\nDec data:");
Serial.print(data[j], DEC);
Serial.print("\nfloat data:");
Serial.print(floatData);
*/
if (result == node.ku8MBSuccess) {
Serial.print("\nSuccess, Received data 0: ");
for (j = 0; j < 2; j++) {
data[j] = node.getResponseBuffer(j);
}
unsigned long temp = (unsigned long)data[0] + (unsigned long)data[1] * 65536;
floatData = *((float*)&temp);
Serial.print(floatData);
}
//}
//}
else {
Serial.print("Failed, Response Code: ");
Serial.print(result, HEX);
Serial.println(" ");
delay(5000); // 5000
}
delay(1000);
}
arduino
modbus
rs485
0 Answers
Your Answer