We are trying to read the "total kWh" register on a Carlo Gavazzi EM340 3-phase meter (Link to manual), using modbus. The Arduino is a Mega 2560, and for the RTU connection we are using this little MAX485 TTL-to-RS485 converter board Link
The cable between the meter and the board is a shielded cable (1m long), with twisted wires, so that should be ok. Ground is connected, see fritz below.
Baudrate on the EM340 is currently set to 9600, but I have tried every single baud value on the EM340 and correspondingly on the Arduino, and still it does not work.
Here is the code, which is based on the ModbusMaster-example:
#include <ModbusMaster.h>
#define MAX485_DE 3
#define MAX485_RE_NEG 2
// instantiate ModbusMaster object
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);
// Modbus slave ID 1
node.begin(1, Serial);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
uint8_t result;
// Read 16 registers starting at 0x3100)
result = node.readInputRegisters(0x0034, 1);
Serial.print("Result: ");Serial.println(result);
if (result == node.ku8MBSuccess)
{
Serial.print("kWh: ");
Serial.println(node.getResponseBuffer(0x00)/100.0f);
}
delay(5000);
}
Fritzing drawing:
Yellow: RO
Green: RE
Blue: DE
Orange: DI
No matter what we try, the result is always "226", which means that the Arduino isn't connecting with the EM340.
We also tried applying a separate 5V power supply for the MAX485-board, still a "226" error.
We also tried all different kinds of registers and both holding and input registers. Nothing.
My gut feeling is that this is not a software error, but something to do with the hardware setup.



