hi,
I am want to read the value from the slave RS485. I am using the following code communication error I am getting a communication error.
Pin configuration is explained below TTL A and B output is given to D- and D+. DE and RE are shorted and given to ground DI is given to TX and RO is given to RX.
do respond to this as soon as possible. I just want to read the RS485 values from the Slave device.
// Include these libraries for using the RS-485 and Modbus functions
#include <RS485.h>
#include <ModbusMaster485.h>
#include <SPI.h>
// Instantiate ModbusMaster object as slave ID 1
ModbusMaster485 node(254);
// Define one addres for reading
#define address 3000
// Define the number of bytes to read
#define bytesQty 100
void setup()
{
pinMode(5, OUTPUT);
digitalWrite(5, LOW);
// Power on the USB for viewing data in the serial monitor
Serial.begin(115200);
delay(100);
// Initialize Modbus communication baud rate
node.begin(19200);
// Print hello message
Serial.println("Modbus communication over RS-485");
delay(100);
}
void loop()
{
// This variable will store the result of the communication
// result = 0 : no errors
// result = 1 : error occurred
int result = node.readHoldingRegisters(address, bytesQty);
if (result != 0) {
// If no response from the slave, print an error message
Serial.println("Communication error");
delay(1000);
}
else {
// If all OK
Serial.print("Read value : ");
// Print the read data from the slave
Serial.print(node.getResponseBuffer(0));
delay(1000);
}
Serial.print("\n");
delay(2000);
// Clear the response buffer
node.clearResponseBuffer();
}