I am trying to communicate with a battery charge controller via RS-485 ModBus RTU half-duplex communication. I am using a Particle Argon and this RS-485 transciever. I can see that the Tx packet is correct and being sent. However, I am getting no response. The charge controller is powered separately so only the A,B, and GND lines are connected.
enter image description here
#include "Particle.h"
SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_THREAD(ENABLED);
//instantiate ModbusMaster object as slave ID 1
ModbusMaster node(1);
unsigned long interval = 0;
unsigned long base_T = 1000;
const int addr = 0x30A0;
void idle() {
delay(10); // in case slave only replies after 10ms
}
void setup() {
// initialize Modbus communication baud rate
node.begin(9600);
node.enableTXpin(D4); //D7 is the pin used to control the TX enable pin of RS485 driver
node.enableDebug(); //Print TX and RX frames out on Serial. Beware, enabling this messes up the timings for RS485 Transactions, causing them to fail.
node.idle(idle); //function gets called in the idle time between transmission of data and response from slave
Serial.begin(9600);
// while(!Serial.available()) Particle.process();
Serial.println("Starting Modbus Transaction:");
}
void loop() {
uint8_t j, result;
uint16_t data[10];
if (millis() - interval > base_T) {
interval = millis();
result = node.readInputRegisters(addr,1);
// do something with data if read is successful
if (result == node.ku8MBSuccess) {
Serial.print("Success, Received data: ");
for (j = 0; j < 2; j++) {
data[j] = node.getResponseBuffer(j);
Serial.print(data[j], HEX);
Serial.print(" ");
}
Serial.println("");
base_T = 1000;
} else {
Serial.print("Failed, Response Code: ");
Serial.print(result);
Serial.print(" - ");
Serial.print(result, HEX);
Serial.println("");
base_T = 5000; //if failed, wait for bit longer, before retrying!
}
}
}
type or paste code here
Does anyone experience using this transceiver or debugging the RS-485 bus? I’ve used a logic analyzer to confirm that the transmitted packet looks as expect leaving the micro but am not sure what to expected the A,B lines of the RS-485 transciever to look like.
afry is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.