Arduino Due + ENC28J60 + Modbus TCP/IP

Hi everyone!

I’m trying to send data through the ENC28J60 module to a PLC with Modbus TCP/IP protocol, the thing is that I don’t have a PLC, and because of this I’m using a Modbus simulator (Modbus Poll). Until now I’ve accomplished to establish the connection between the Modbus simulator and the module ENC28J60, but it only works for the first data send, for the next data sends, the Modbus simulator shows “read error”.

I’m using this libraries: UIPEthernet, Modbus and ModbusIP. I’ve only maked one change to ModbusIP library, in ModbusIP.h file I replaced the include of Ethernet.h for UIPEthernet.h, because Ethernet library only works for WIZnet based modules (W5100/W5200/W5500). I’ve seen a lot of examples of Arduino and PLC communication with Modbus TCP/IP, but in Arduino UNO, they use EtherCard, Modbus and ModbusIP_ENC28J60 libraries, and looks like it works perfectly for them, but the problem is that EtherCard library only works for AVR based modules and the same is for ModbusIP_ENC28J60 library because it depends of EtherCard library.

Here is the code:

#include <Modbus.h>
#include <ModbusIP.h>
#include <SPI.h>
#include <UIPEthernet.h>

//Modbus Registers Offsets (0-9999)
const int SENSOR_IREG = 100;

//ModbusIP object
ModbusIP mb;

int count = 0;

void setup()
{
    // The media access control (ethernet hardware) address for the shield
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

    // The IP address for the shield
    byte ip[] = { 192, 168, 0, 120 };

    //Config Modbus IP
    mb.config(mac, ip);

    // Add SENSOR_IREG register - Use addIreg() for analog Inputs
    mb.addIreg(SENSOR_IREG);
}

void loop()
{
    //Call once inside loop() - all magic here
    mb.task();

    mb.Ireg(SENSOR_IREG, count);

    count++;

    delay(500);
}

Finally the Modbus Poll configuration is attached.

Any ideas or help will be greatly appreciated.

I have also the same issue, simulated with Modscan and it reads Arduino only once, then “connection terminated” warning appears. Did you fix it?