Skip to content

Can not communicate with ArduinoMega2560 #33

Open
@hannasy-id

Description

@hannasy-id

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); 
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions