i have an arduino UNO with RS485 module.
And i have an problem with communication of this module with power meter "InePro PRO-1Mod" (datasheet) over ModBus protocol. I want for example read an L1 Voltage value, which i know from the manual (page 24 & 25) that this value is stored in "read holding register" with adrress 5002. I should communicate with these paramaters:
- Baud rate 9600
- 8 data bits
- even parity
- 1 stop bit
There is also mention about 120 ohms resistor placed by the power meter (but it is 15cm long cable, and even with the resistor there is no change)
I have tried using many of ModBus libraries and for now none of them doesn't work. I have tried "Modbus-Master-Slave-for-Arduino" , "ModbusMaster and now at last i am using this "simple-modbus".
I think that with that simple modbus library i went far as i can, but it is still doesn't working, but i see on the display of power meter that there is some try to communication (i see a black dot which shows modbus communication) but i don't receive any useful data.
I am using this code:
#include <SimpleModbusMaster.h>
#include <AltSoftSerial.h>
#define TxEnablePin 2 // RS485 modbus direction control pin:
#define baud 9600 // modbus port speed:
#define timeout 1000 // modbus timeout in mSec:
#define polling 500 // modbus scan rate in mSec:
#define retry_count 15
#define TOTAL_NO_OF_REGISTERS 1// number of registers to poll for:
AltSoftSerial altSerial;
enum
{
PACKET1,
TOTAL_NO_OF_PACKETS // leave this last entry
};
Packet packets[TOTAL_NO_OF_PACKETS]; // array of Packets to be configured
//struct packetPointer packet1 = &packets[PACKET1];
unsigned int regs[TOTAL_NO_OF_REGISTERS]; // master register array
long previousMillis = 0;
long interval = 1200;
unsigned long currentMillis;
void setup() {
Serial.begin(9600);
altSerial.begin(9600);
altSerial.println("Hello World");
modbus_construct(&packets[PACKET1], 5, READ_HOLDING_REGISTERS, 5000, 2, 0); //initialize packet
modbus_configure(&Serial, baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
}
void loop() {
modbus_update();
float Power;
unsigned long temp = (unsigned long)regs[1] << 16 | regs[0];
Power = *(float*)&temp;
currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
altSerial.print("Exception errors: ");
altSerial.println(packets[PACKET1].exception_errors);
altSerial.print("Failed requests: ");
altSerial.println(packets[PACKET1].failed_requests);
altSerial.print("Successful requests: ");
altSerial.println(packets[PACKET1].successful_requests);
altSerial.print("Low byte: ");
altSerial.println(regs[0]);
altSerial.print("High byte: ");
altSerial.println(regs[1]);
altSerial.print("Power ");
altSerial.println(Power);
altSerial.println("----------");
previousMillis = currentMillis;
}
}
And i have got only this output in the pc (its repeating of course):
----------
Exception errors: 0
Failed requests: 5
Successful requests: 0
Low byte: 0
High byte: 260
Power 0.00
----------
Altserial library i am using together with USB2TTL convertor on pins 8 & 9, to see output.
I should mention that there is only A and B screw terminals on power meter, so i have no option to make common ground connection. I also using an 15cm twisted pair cable UTP.
Can someone help me to make it work ? I have tried to change adrress of holding register to 0x5000 or 5002, tried changing number of registers.
I have tried to connect rs485 module with USB2TTL to pc and run software called "qModMaster" and it works, but with arduino it doesn't work.
Slave ID (power meter) is 5.
Thank you, for your help.