Go Down

Topic: Need help with Modbus Communication  (Read 2035 times) previous topic - next topic

smpandidurai

hello,

im trying to communicate a controller with RS485 Modbus RTU using Arduino Mega2560

#include <Wire.h>
#include <SimpleModbusMaster.h>
#include <SoftwareSerial.h>
////////// Prot information ////////////
#define baud 9600  //The speed at which the data is set at the device
#define timeout 100 //Check Scan Time OUT.
#define polling 100 //the scan rate.
#define retry_count 10 //Check 10 rounds
#define TxEnablePin 2 //Use pin 2 on the Arduino Mega 2560 board as a control pin for receiving-sending data.
#define TOTAL_NO_OF_REGISTERS 13 //Use 1 register numbers.

enum //Collect the number of registers in batches
{
  PACKET1,
  //PACKET2,
  //PACKET3,
 // PACKET4,
  //PACKET2,
  TOTAL_NO_OF_PACKETS //leave this last entry.
};

Packet packets[TOTAL_NO_OF_PACKETS]; //Bring information, information together
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{
  Serial.begin(9600);
  modbus_construct(&packets[PACKET1], 3, READ_INPUT_REGISTERS,30000,6,10); // The first 1 is the position of the device to be read / 512 Is the position value Register.
  modbus_configure(&Serial1, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);   //Set the value according to the device used to read the value.
}

void loop() {
  modbus_update(); //To bring the function modbus_update used
  float RDSS;
  RDSS = regs[10];
  Serial.print("READ = ");
  Serial.println(RDSS);
  //Serial.println(regs[0]);
  /*Serial.println(regs[2]);
  Serial.println(regs[3]);
  Serial.println(regs[4]);
  Serial.println(regs[5]);
  Serial.println(regs[6]);
  Serial.println(regs[7]);
  Serial.println(regs[8]);
  Serial.println(regs[9]);
  Serial.println(regs[10]);
  Serial.println(regs[11]);
  Serial.println(regs[12]);*/
 
 
  delay(1000);
}

that is my code which i got from searching online for very long time and that is not working and giving me some random number
kindly help me out with this

Thank you

Go Up