RS-485 Modbus communication between PLC and Photon

Hi,

I’m looking to use a photon to receive status data from a PLC using Modbus. I’m a beginner to both RS-485 and Modbus so I’m simply trying to pass a string from the PLC to the Photon. I have the following hardware:

PLC configured to send 8 registers storing “hellowor”:

https://www.automationdirect.com/adc/shopping/catalog/programmable_controllers/click_series_plcs_(stackable_micro_brick)/plc_units

A MAX485 Breakout:

A Photon programmed with the ModbusMaster example code (and a change to the holding register address).

I always receive a ‘E0’ code after a failed response. I’m willing to add code samples, wiring pictures and plc config pictures, but I held off because, as I’m new to this, I don’t know where to begin with my debugging.

hi,

  1. We will need some more details, wiring, plc conf. and your .ino code for modbusMaster.

  2. this module appears as not well documented also reviews show that is not easy to drive this module could you consider to use, for example, this instead.

  3. when you done with above I’ll will try to help you more :slight_smile:

I will start by ordering the a better document module as you suggested and do a clean build with that and snap some pictures and post the code.

I suspected that module was cheap and would be difficult to communicate from the start but got sold on the price. Expect and update on this next week with the details.

1 Like

Ok, I finally got around to setting things up with a SparkFun RS485 Breakout.

Here’s my wiring:

Here’s my Photon code:

/*
 * Project modbus-test
 * Description: Particle firmware to test communications between a PLC's RS485 connection via MODBUS
 * Author: Ryan Kast
 * Date: 1/29/19
 */

#include "ModbusMaster.h"

// instantiate ModbusMaster object as slave ID 1
ModbusMaster node(Serial1, 1);

// setup() runs once, when the device is first turned on.
void setup() {
  // Put initialization like pinMode and begin functions here.
  // initialize Modbus communication baud rate
	node.begin(9600);
	node.enableTXpin(D7); //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.

	Serial.begin(9600);
	while(!Serial.available()) Particle.process();
	Serial.println("Starting Modbus Transaction:");
}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
  // The core of your code will likely live here.
	uint8_t j, result;
	uint16_t data[10];

	result = node.readHoldingRegisters(0x00,8);

	Serial.println("");

	// do something with data if read is successful
	if (result == node.ku8MBSuccess) {
		Serial.print("Success, Received data: ");
		for (j = 0; j < 8; 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); //if failed, wait for bit longer, before retrying!
	}
	delay(5000);
	/*
	if( node.available() > 0 ){

			uint16_t data = node.receive();
			Serial.print(data, HEX);
	}
	*/
}

And here’s some screenshots of the PLC software configuration:
comPortConfig

Hi, the good start point is here. Please read this is really helpful
also I’m confused a little what are you trying to achieve ?

Please specify as many details as you can !

Looks like your PLC conf. and Photon , both acting as Modbus master. If you want just to read some registers from PLC your PLC has to be configured as slave and then Photon will act as master periodically read/set registers. Also your SparkFun RS485 Breakout is half-duplex that’s mean that you have to take responsibility for communication at all I mean you have to control when this RS485 converter has to act as sender and when as receiver in your Photon program.
I don’t have this PLC but I have some RSlogix5000 also some moxa RS232 to RS485 if time allow me during this weekend I’ll try first get some Modbus slave software emulator and then make some tests and if all will work i’m gonna try to read some registers from my RSlogix.

Please be patient as this project can take a little