So I am using the Arduino MKR 1010 board along with a Arduino MKR RS485 shield in order to make the arduino communicate using Modbus. My goal it to set the Arduino board as a slave and have it communicate with a PLC. However I can no seem to get the communication between the two connected. I have tried using different cables and even a different arduino (MKR Zero). I have tried many different library example codes such as ARDUINO485, ModbusRTUSlave and ModbusRTUMaster. I have the code that I have most recently been working with in this post. Any help would be greatly appreciated!
#include <ArduinoRS485.h>
#include <ArduinoModbus.h>
uint16_t TEST = 40;
int packetReceived;
void setup() {
Serial.begin(9600);
// start the Modbus RTU server, with slave id 1
if (!ModbusRTUServer.begin(1, 19200, SERIAL_8E1)) {
Serial.println("Failed to start Modbus RTU Server!");
while (1);
}
// configure a group of holding registers
ModbusRTUServer.configureHoldingRegisters(53249,100);
// Writes to a single holding register
ModbusRTUServer.holdingRegisterWrite(53249, TEST);
ModbusRTUServer.holdingRegisterWrite(53250, TEST);
ModbusRTUServer.holdingRegisterWrite(53251, TEST);
}
void loop() {
// poll for Modbus RTU requests
packetReceived = ModbusRTUServer.poll();
if(packetReceived) {
Serial.println("Request Received!");
}
else{
Serial.println("No package Received!");
}
delay(100);
}