Dear all,
I am trying to create communication between an arduino Mega and a modbus RTU energy meter by using a MAX485 module.
Firstly, I have checked adresses by usine Modbus doctor and results are following:
As a consequence, slave adress is 0x4B
And register adress is 0x111
When I try this code with on arduino MEGA:
#define DE 3
#define RE 2
ModbusMaster node;
void preTransmission()
{
digitalWrite(DE,1);
digitalWrite(RE,1);
}
void postTransmission()
{
digitalWrite(DE,0);
digitalWrite(RE,0);
}
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
pinMode(DE,OUTPUT);
pinMode(RE,OUTPUT);
digitalWrite(DE,0);
digitalWrite(RE,0);
node.begin(0x4B,Serial1);
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
uint8_t Resultat;
Resultat = node.readHoldingRegisters(0x111, 16);
if (Resultat == node.ku8MBSuccess)
{
Serial.print("connexion");
Serial.println(Resultat);
}
else
{
Serial.print("Echec:");
Serial.println(Resultat);
}
delay(1000);
}
The Serial response is always 226. I do not suceed to discuss with the energy meter.
Can you help me?
Thank you by advance