Server.begin() FAILS

Hello,

I just bought an Arduino UNO Rev3, and this W5500 ethernet module to go with it. I used the diagram from the Ethernet library to connect the ethernet module and the Arduino. I'm also using the "WebServer" example, provided by the IDE, to configure the Arduino as a web server. I haven't done any modifications to the code, except changing the IP address and adding a few print statements for debugging.

When I upload the code, I can successfully ping the Arduino from my computer, so IP stack is good:

$ ping -c3 10.200.40.199
PING 10.200.40.199 (10.200.40.199) 56(84) bytes of data.
64 bytes from 10.200.40.199: icmp_seq=1 ttl=128 time=0.241 ms
64 bytes from 10.200.40.199: icmp_seq=2 ttl=128 time=0.242 ms
64 bytes from 10.200.40.199: icmp_seq=3 ttl=128 time=0.241 ms

--- 10.200.40.199 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2062ms
rtt min/avg/max/mdev = 0.241/0.241/0.242/0.000 ms

However, when I try a TCP connection to port 80, the connection is refused by Arduino:

$ nc -vw2 10.200.40.199 80
nc: connect to 10.200.40.199 port 80 (tcp) failed: Connection refused

I'm using the latest version of the Ethernet library (v2.0.2). After some troubleshooting, I noticed that the server.begin() function fails, but I haven't been able to find any details on why. The function doesn't return anything, so I'm kind of stuck and would appreciate some help.

Here's the truncated version of the "WebServer" example and what I'm uploading to the Arduino:

/*
 Web Server

 A simple web server that shows the value of the analog input pins.
 using an Arduino WIZnet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 02 Sept 2015
 by Arturo Guadalupi
 
 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(10, 200, 40, 199);

EthernetServer server(80);

void setup() {
  Ethernet.init(10);  // Most Arduino shields

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("Ethernet WebServer Example");

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);

  // Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }

  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  if(Ethernet.hardwareStatus() == EthernetW5500) {
    Serial.println("Hardware is W5500");
  }

  if(Ethernet.linkStatus() == LinkON) {
    Serial.println("Link is ON");
  }

  // start the server
  server.begin();
  if(!server) {
    Serial.println("Server is NOT listening...");
  }
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();

  if (client) {
    Serial.println("new client");
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

Here's the serial output:

Ethernet WebServer Example
Hardware is W5500
Link is ON
Server is NOT listening...
server is at 10.200.40.199

What am I doing wrong here?

If it's a webserver, shouldn't port 80 be mentioned somewhere, maybe in begin.server(80);
Not my specialty, but I have seen that syntax a lot and it is missing here, soooooo

This line creates the server and specifies the port it'll listen on

EthernetServer server(80);

Then server.begin() is supposed to tell it to begin listening for requests, but that's the part that fails...

Have you downloaded and installed the Wiznet library?

The standard IDE ethernet library supports only the w5100, so you need that library because explicitly supports your WIZ550io-W5500.
Give it a try.

I agree that server.begin() reports if initialisation went ok. But you dont check the result of .begin - you check the object instead.

I suggest you start with an working example from the IDE.

@docdoc good suggestion! I looked at the Wiznet library, but didn't get anywhere unfortunately. I was able to further debug the module though. FWIW, I think the standard ethernet library universally supports W5x00 chips, at least according to this comment in the header file:

// w5100.h contains private W5x00 hardware "driver" level definitions
// which are not meant to be exposed to other libraries or Arduino users

There are also a few other mentions of W5500 in the header file, which tells me it should be supported. Regardless, I did play around with the Wiznet library too, but didn't get any further. Both libraries have the same register definitions, as far as I could tell from the header files. I narrowed it down to an issue with writing to the command register (0x0001). No matter what value I try to write, it always comes back as 0 (CLOSED).

#include <utility/w5100.h>

void testSocket(uint8_t socketNum, uint16_t port) {
  // close socket if it's in use - not sure if it works because the socket is always closed
  W5100.writeSnCR(socketNum, Sock_CLOSE);
  delayMicroseconds(1);
  while (W5100.readSnCR(socketNum)) {}
  Serial.print("After CLOSE, STATUS: 0x");
  Serial.println(W5100.readSnSR(socketNum), HEX);

  // set mode to TCP - WORKS!
  W5100.writeSnMR(socketNum, SnMR::TCP);
  Serial.print("MODE: 0x");
  Serial.println(W5100.readSnMR(0), HEX);

  // set source port - WORKS!
  W5100.writeSnPORT(socketNum, port);
  Serial.print("SPORT: ");
  Serial.println(W5100.readSnPORT(socketNum));

  // open socket (INIT) - FAILS!
  W5100.writeSnCR(socketNum, Sock_OPEN);
  delayMicroseconds(1);
  while (W5100.readSnCR(socketNum)) {}
  Serial.print("STATUS: ");
  Serial.println(W5100.readSnSR(socketNum));
}

output:

EtheServer Example
Ethernet WebServer Example
After CLOSE, STATUS: 0x0
MODE: 0x21 (TCP)
SPORT: 80
STATUS: 0

I'm gonna say the module is trash. I'll order some other one and report back in a few days. I appreciate the help!

No, afaik W5500 has a totally different structure and can't be used with the standard Ethernet library, at least it could fail some functions (and the W5500 has more features than the 5100, just to say, the 5500 has ability to detect and report the Ethernet link status to Arduino while 5100 doesn't).

I have such a modul like linked by the TO and another one specific for the Nano Classic.
Both identify as W5500 and for both I just use the Ethernet Library from the Arduino Core.