Modbus Serial giberish

Hello all,

I'm working on a BMS (Building managment system) using an UNO and MAX485 as the Master to talk with a RADA OUTLOOK shower. I followed Anthony Cartwright's tutorial for communicating with his solar inverter but adapted the code to talk with my OUTLOOK network box.

which appears to be this example modified:
http://4-20ma.io/ModbusMaster/examples_2_r_s485__half_duplex_2_r_s485__half_duplex_8ino-example.html#a6

The baud rate for the OUTLOOK is 9600 in the manual. I set my serial monitor to 9600 but all i get is giberish in between my dashes. I've looked at other forums and they mostly indicate that the baud rate is wrong and is causing the issue. i've tried fix/repair in v1.8 but i'm currently the Arduino IDE 2.0.0. The OUTLOOK supports read holding register (0x03). and i'm atempting to get an outlet temperature (Register 31) in C. the dashes print out but it's just giberish in between.

Am i using Modbusmaster wrong?

Current pin out is:
MAX485 -
VCC - 5V,
GND - GND,
A - D+,
B - D-,
0V - GND
DI - TX,
DE - 3,
RE - 2,
RO, RX


#define MAX485_DE 3
#define MAX485_RE_NEG 2

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);

  //INIT IN RECIEVE MODE
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

  //MODBUS COMMS RUNS AT 115200 BAUD
  Serial.begin(9600);

  //MODBUS SLAVE ID 1
  node.begin(1, Serial);

  //CALLBACKS ALLOW US TO CONFIGURE THE RS485 TRANCIEVER CORRECTLY
  delay(3);
  node.preTransmission(preTransmission);
  delay(3);
  node.postTransmission(postTransmission);
}

void loop() {

  uint8_t resultMain;

  resultMain = node.readHoldingRegisters(0x031, 1);

  if (resultMain == node.ku8MBSuccess) {

    Serial.print("---------");
    Serial.println(node.getResponseBuffer(0x000));
    Serial.print("- - - - -");
  }
  delay(1000);
}

image

The garbage is the binary modbus data. You are using the hardware serial port for both debugging and modbus. On an Uno, you can use a software serial port for your modbus comms.

Thank you for your quick response. I've finally had a look at the code and added a software serial port out of pins 10 & 11. i changed my modbus master to my software serial. my read out is a bit better and i feel i'm getting closer but still not there. Am i closer?

#include <SoftwareSerial.h>

#define MAX485_DE 3
#define MAX485_RE_NEG 2

const byte rxPin = 10;
const byte txPin = 11;

SoftwareSerial mSerial (rxPin, txPin);

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(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  pinMode(MAX485_RE_NEG, OUTPUT);
  pinMode(MAX485_DE, OUTPUT);

  //INIT IN RECIEVE MODE
  digitalWrite(MAX485_RE_NEG, 0);
  digitalWrite(MAX485_DE, 0);

  //MODBUS COMMS RUNS AT 115200 BAUD
  Serial.begin(9600);
  mSerial.begin(9600);

  //MODBUS SLAVE ID 1
  node.begin(1, mSerial);

  //CALLBACKS ALLOW US TO CONFIGURE THE RS485 TRANCIEVER CORRECTLY
  //delay(3);
  node.preTransmission(preTransmission);
  //delay(3);
  node.postTransmission(postTransmission);
}

void loop() {

  if (mSerial.available()){
    mSerial.read();
    Serial.print("test");
  }

  uint8_t resultMain;

  resultMain = node.readHoldingRegisters(0x031, 1);

  if (resultMain == node.ku8MBSuccess) {

    Serial.println("- - - - - -");
    Serial.println(node.getResponseBuffer(0x000));
    Serial.println("- - - - - -");
  }
  delay(1000);
}

I don't think you need these 2 lines - they should be handled by the SoftwareSerial library.

I suspect that this code may either do nothing, or mess up your Modbus comms. You don't need it so remove it.

What does "is a bit better" mean? What serial output do you get?

You should print out the value of resultMain if the call failed.

Thanks for everyones replies.

@markd833 i removed those lines and it didn't seem to have any effect other than it didn't break the program. so you were right that the serial library took care of the input/output

@pylon this is with Serial.println(node.getRsponeBuffer(0x000));:

And this is with Serial.println(resultMain);:

This is the register i'm trying to access:

Register 0x031 is not register 31! 0x031 == 49!

Wow that's embarassing. Thank you @pylon, I'm getting different responses now. They don't seem correct but i do seem to have found a clock that is counting up at register 0x121. I'll mess around with this for a while. Thanks for all of your help everyone!

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