Problems with Arduino Uno and Wiznet WIZ811MJ

Having problems getting a WIZ811MJ (W5100) working with the Arduino Uno. I seem to get garbage sending/receiving data using TCP. TCP connections seem to work ok, ping works fine too. But when client connects and I attempt to send data to it, the client gets a bunch of garbage but then followed by the data I sent. Subsequent sends are fine on the same connection, but this always happens during the first TX of the connection. And I can’t receive data at all - just a constant stream of noise. Any thoughts? bad wiznet board?

Here’s my setup:

J1-1 (MOSI) to D11
J1-2 (MISO) to D12
J2-1 (3.3) to 3.3v
J2-3 (SCLK) to D13
J2-4 (/SCS) to D10
J2-9 (GND) to Ground
J2-2 (/RESET) to Reset

And this code basically spews garbage once a client connects:

#include <SPI.h>
#include <stdint.h>
#include <Udp.h>
#include <Ethernet.h>
#include <Client.h>
#include <Server.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[]  = { 192, 168, 1, 27 };
byte gateway[] = { 192, 168, 1, 1 };
byte subnet[] = { 255, 255, 255, 0 };

Server server(80);

void setup() {
  Serial.begin(9600);
  
  Ethernet.begin(mac, ip, gateway, subnet);
  server.begin();
}

void loop() {
  Client client = server.available();
  if (client) {
    while(client.connected()) {
      if (client.available()) {
        int in = client.read();
        Serial.write(in);
      }
    }
    delay(1);
    client.stop();
  }
}

Figured it out!

I’m guessing there’s some sort of compiler-time optimization that’s screwing up w5100. The patch below fixes my problem.

*** w5100.h.old 2011-10-02 16:40:09.046682039 -0400
--- w5100.h     2011-10-02 17:05:05.586684666 -0400
***************
*** 258,264 ****
    }                                                          \
    static uint16_t read##name(SOCKET _s) {                    \
      uint16_t res = readSn(_s, address);                      \
!     res = (res << 8) + readSn(_s, address + 1);              \
      return res;                                              \
    }
  #define __SOCKET_REGISTER_N(name, address, size)             \
--- 258,265 ----
    }                                                          \
    static uint16_t read##name(SOCKET _s) {                    \
      uint16_t res = readSn(_s, address);                      \
!     uint16_t res2 = readSn(_s, address + 1);                 \
!     res = (res << 8) + res2;                                 \
      return res;                                              \
    }
  #define __SOCKET_REGISTER_N(name, address, size)             \

$ avr-gcc -v
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.5.3/lto-wrapper
Target: avr
Configured with: …/src/configure -v --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-checking --disable-libssp --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=avr
Thread model: single
gcc version 4.5.3 (GCC)