I've been thinking about this and it seems that it would be useful if there were a way of monitoring the RS485 bus when messages were being sent and hopefully received.
This bit of code is for an Arduino UNO using a software serial port (AltSoftSerial) to listen in on the RS485 bus. It is limited to a RS485 bus speed of 19200 baud (actually a bit higher, but not 38400).
// RS485 Monitor Demo - Arduino UNO
//
// Uses AltSoftSerial library for a software serial port for RS485 comms
// Get it at https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
// Software serial Tx = pin 9 , Rx = pin 8
//
// RS485 DI signal to pin 9
// RS485 RO signal to pin 8
// RS485 RE signal to pin 7
// RS485 DE signal to pin 6
// RS485 VCC to 5V
// RS485 GND to GND
//
#include <AltSoftSerial.h>
AltSoftSerial softSerial; // software serial port - for RS485
#define RE_PIN 7
#define DE_PIN 6
uint8_t rxByteCount = 0;
void setup() {
Serial.begin(115200);
softSerial.begin(9600);
pinMode(RE_PIN, OUTPUT);
pinMode(DE_PIN, OUTPUT);
digitalWrite(RE_PIN, LOW); // Enable RS485 receiver
digitalWrite(DE_PIN, LOW); // Disable RS485 transmitter
Serial.println(F("Ready for data."));
}
void loop() {
uint8_t rxByte;
if (softSerial.available()) {
rxByte = softSerial.read();
rxByteCount++;
Serial.print((rxByte >> 4) & 0x0F, HEX);
Serial.print(rxByte & 0x0F, HEX);
Serial.print(" ");
}
if ( rxByteCount > 15 ) {
rxByteCount = 0;
Serial.println();
}
}
If you have a spare Arduino UNO and MAX485 line driver board, then you can use it to listen in to the bytes on the bus. It prints them out in hexadecimal. Just extend your bus to wire up the extra RS485 module.
You should then be able to watch what your code sends out and the response coming back.
Hopefully it will help you in debugging where the problem might be.

