Modbus Communication using shield doesn't work

I'm attempting to use an Arduino uno with a DFR0259 rs485 shield to communicate to a slave device through Modbus protocol but nothing seems to work. The library i'm using is ModbusMaster. To test the communication i'm using the modbus slave program which is receiving Rx signals but no data is being written. Some help would be greatly appreciated.

#include <ModbusMaster.h>

#define MAX485_DE      4
#define MAX485_RE_NEG  5

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);
  
  digitalWrite(MAX485_RE_NEG, 0);

  digitalWrite(MAX485_DE, 0);

  Serial.begin(19200);             //Baud Rate as 19200

  node.begin(1, Serial);            //Slave ID as 1

  node.preTransmission(preTransmission);

  node.postTransmission(postTransmission);

}

void loop()

{
  node.writeSingleRegister (0x40001, 200);
}

Can you describe in more detail what that means? Aren't you communicating with that device you mentioned? If that device is currently an Arduino, please post the code you use there for testing.

The manual of that device is probably needed to help you because details of the Modbus implementation may be relevant.

One example:

Probably the register at 0x40001 doesn't exist but is actually a holding register at address 1. The different bases are used by PLC manufacturers because they don't have a way to specify the type of register, so they use the address range to determine the register type and therefor the Modbus function to use.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.