0

I've been trying to interface between a NodeMCU and a Dotech DPX200 Pressure Multi-Switch over Modbus RS485 using a MAX485 Module and after a few suggestions I managed to communicate with the Simply Modbus Slave simulator.

The DPX200 should have a Slave ID of 1 by default and I'm trying to read the data with function 3 in address 40023 to 40027, but with the same code and wiring as shown below it gives me a Timeout error on connecting to the DPX200 itself.


I've added the DPX200's Manual link with my NodeMCU script and wiring diagram, and would appreciate any help from you.

Wiring Diagram

#include <ModbusMaster.h>
#include <SoftwareSerial.h>

#define MAX485_TX_ENABLE  12

String tmpstr2;
int myInts[6];
SoftwareSerial SoftSerial(5, 4);
ModbusMaster node;

void preTransmission(){
  digitalWrite(MAX485_TX_ENABLE, 1);
}

void postTransmission(){
  digitalWrite(MAX485_TX_ENABLE, 0);
}

void setup(){
  SoftSerial.begin(9600);
  Serial.begin(9600, SERIAL_8N1);
  pinMode(MAX485_TX_ENABLE, OUTPUT);
  digitalWrite(MAX485_TX_ENABLE, 0);
  node.begin(1, SoftSerial);
}

void loop(){
  uint16_t k = 0,Status;
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission); 
  Status = node.readHoldingRegisters(22, 5); //Since address is 40023 to 40027
  if ( (Status == node.ku8MBSuccess) ){
     Serial.println("\nValues: ");
     Serial.println(node.getResponseBuffer(0));
     node.getResponseBuffer(0));
     Serial.println(node.getResponseBuffer(1));
     node.getResponseBuffer(1));
     Serial.println(node.getResponseBuffer(3));
     node.getResponseBuffer(3));
     Serial.println(node.getResponseBuffer(4));
     node.getResponseBuffer(4));
  }
  else if (Status == node.ku8MBIllegalDataAddress) {
     Serial.println("");
     Serial.println("IllAddr");
  } 
  else if (Status == node.ku8MBIllegalDataValue) {
     Serial.println("");
     Serial.println("IllValue");
  } 
  else if (Status == node.ku8MBSlaveDeviceFailure) {
     Serial.println("");
     Serial.println("SlaveFAIL");
  } 
  else if (Status == node.ku8MBInvalidSlaveID) {
     Serial.println("");
     Serial.println("InvalSlave");
  } 
  else if (Status == node.ku8MBInvalidFunction) {
     Serial.println(""); 
     Serial.println("InvalFunc");
  } 
  else if (Status == node.ku8MBResponseTimedOut) {
     Serial.println(""); 
     Serial.println("TIMEOUT");
  } 
  else if (Status == node.ku8MBInvalidCRC) {
     Serial.println("");
     Serial.println("CRC");
  }
  delay(6000);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.