RS485 not working with ABB Inverter

Hi Guys,
I’m trying to connect my electron with ABB inverter via RS485 since one month. But I end up with failure continuously. I have copied my code below along with the datasheet. I’ll be happy if someone helps me out.

#include "ModbusMaster.h"

ModbusMaster node(1);


void setup() {
	node.begin(19200);
	node.enableTXpin(D7);
	
	Serial.begin(9600);
	while(!Serial.available()) Particle.process();
	Serial.println("Starting Modbus Transaction:");
}


void loop() {
	static uint32_t i;
	uint8_t j, result;
	uint16_t data[10];

	i++;

	result = node.readHoldingRegisters(40104,2);

	Serial.println("");
	
	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("");
	} else {
		Serial.print("Failed, Response Code: ");
		Serial.print(result, HEX); 
		Serial.println("");
		delay(1000); 
	}
	delay(500);
}

node.readHoldingRegisters(40104,2);

This is probably the wrong address here, as holding registers start from 40000, the method already adds 40000. You have to use node.readHoldingRegisters(104,2); (or 103, there are two conventions for modbus register numbering, starting from 0 or from 1).

If there are more failures, continuing with trial and error will be hard. Try the following steps:

  • Make sure that your inverters modbus port is working properly. If you did not do this already, get a USB <-> RS485 adapter and use a modbus client for your pc for example.
  • After having a working connection with your pc to the inverter, sniff one of the modbus requests your pc is sending with a serial terminal app.
  • Take your Particle again and sniff one of its modbus request packets.
  • Compare both. Modbus rtu is easy to decode, just google the packet format and look at both packets. The difference between both helps to tell what you have to change in your code.

Thanks for your Reply Nils.
I tried with the modscan software. It works perfectly. But when it comes to Particle it didn’t work. I’ll try your suggestions and work on it. Thanks again!

Can you share here how you have connected the Electron to the RS485 adaptor and RS485 lines from your ABB inverter and how you are driving the RS485 adaptor - I have used an adaptor that works fine to talk RS485 to a controller board but it took a little effort to get it working.

Thanks for the Reply armor.

I connected the Rx and Tx pins of the electron to DO and DI of the Max485 chip. Then A and B of the Inverter to A and B of the Max485.

Can you please share the details and how you got it working. It would help me a lot.

Have you already verified if your own circuit with the max485 is working?

If not, just create a simple Particle test app which sends out some known chars over serial and check if you can receive them on the RS485 end, for example with a USB/RS485 converter.

It works perfectly Nils. I used it as a slave and the slave code works with Arduino Uno without any problem. But the master isn’t working.

What about the DE and RE? these need to connected together and attached to a pin on the electron - the RS485 driver should either pull-up or pull-down can’t remember which at the moment.

A + X and B + Y wires should be connected together - at least that’s how it worked for me.

DE and RE are connected to D7 of the electron. The output of RS485 from the inverter are just 2 pins, A and B. So I had it all connected.

OK - so suggest you follow @nils debug approach. BTW, is this the first time you have used the library?

Yeah this is my first time. Hardware side is all perfect. I checked twice. But the problem is with the software. Can you please share any of your code along with the library so that it would be very helpful.

I am not using the Modbus library only a RS485 driver plus a custom controller board API. Sorry.

I think other code won’t help as your library usage looks fine for me, except for the wrong register address.

As already suggested, please record and show the actual binary request packets your modscan software and your Particle board are sending out. Without these packets I see no way to tell what you are doing wrong with the library.

1 Like

Sure, I’ll do it soon and show you.