ArduinoModbus icon indicating copy to clipboard operation
ArduinoModbus copied to clipboard

Can not communicate with ArduinoMega2560

Open hannasy-id opened this issue 4 years ago • 0 comments

I try this library to Arduino Mega 2560, but can not respond, and i try to arduino nano it success.

#include <ArduinoRS485.h> // ArduinoModbus depends on the ArduinoRS485 library
#include <ArduinoModbus.h>

const int numCoils = 10;
const int numDiscreteInputs = 10;
const int numHoldingRegisters = 10;
const int numInputRegisters = 10;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  if (!ModbusRTUServer.begin(1, 9600)) {
    //Serial.println("Failed to start Modbus RTU Server!");
    while (1);
  }

  ModbusRTUServer.configureHoldingRegisters(0x00, numHoldingRegisters);
  
}

void loop() {
  ModbusRTUServer.poll();
  
  // put your main code here, to run repeatedly:
  for (int i = 0; i < numHoldingRegisters; i++) {
    ModbusRTUServer.holdingRegisterWrite(i, 12345); 
  }
}

hannasy-id avatar Aug 19 '20 12:08 hannasy-id