Hi everyone,
I'm working on a project that requires to read some holding registers from a Modbus RTU Slave.
Right now i'm using Arduino Uno R3, the C25B TTL to RS485 module and a ABB M1M Meter with Modbus RTU communication (Addres 1, Parity No, Stop Bits 1-2).
The serial monitor indicates error E0, wich according to the library ( Modbus Master Library )
static const uint8_t ModbusMaster::ku8MBInvalidSlaveID = 0xE0
ModbusMaster invalid response slave ID exception.
But, the slave actually shows on display "Trans" during the modbus intent of reading... The register i wan to read has the address 40103, its a float value.
The wiring is:
Arduino UNO - 5 to C25B - RO
Arduino UNO - 6 to C25B - DI
Arduino UNO - 9 to C25B - RE
Arduino UNO - 10 to C25B - DE
Arduino UNO - 5V to C25B - VCC
Arduino UNO - GND to C25B - GND
The code i'm working on, is this:
#include <ModbusMaster.h>
#include <SoftwareSerial.h>
#define MAX485_RE_NEG 9
#define MAX485_DE 10
//define the rx and tx for Serial1
const byte rxPin =5;
const byte txPin =6;
SoftwareSerial Serial1 (rxPin, txPin); //Define another Serial channel, to use the main for debuggin
ModbusMaster node; // Define a ModbusMaster object called 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);
Serial1.begin(9600); //Define both serial channels at 9600 bps
node.begin(1, Serial1); //Start the serial comm over node object, with Serial1...
node.preTransmission(preTransmission);
node.postTransmission(postTransmission);
}
void loop()
{
uint8_t ResultadoLectura;
ResultadoLectura = node.readHoldingRegisters(0x40103, 8); //Read the 40103 address and 8 registers ahead
if (ResultadoLectura == node.ku8MBSuccess)
{
Serial.print("\nReading in holding registers: ");
Serial.println(node.getResponseBuffer(0));
}
else {
Serial.print("\nConnection error: ");
Serial.print(ResultadoLectura, HEX);
Serial.print(" , ");
Serial.println( ResultadoLectura);
}
delay(3000);
}
Can anyone see something that i'm missing?
Thanks for your support, have a great day