Ethernet issue with PLC based on ATmega1602

You should change this. It may not be your problem now, but it probably will at some point.

//change this
  Ethernet.begin(mac, ip,gateway,subnet);

// to this
  Ethernet.begin(mac, ip,gateway,gateway,subnet);