SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
#134120
Having problems transmitting and receiving data from Arduino Uno to the WIZ811MJ using the Ethernet lib. Socket connection protocol seems fine (listening, connecting, etc.), ping is fine, but when I transmit data using TCP I get a ton of garbage sent to the client before my data is sent. Receiving data is worse. I ONLY get garbage received, even when I don't send anything from the client.

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 example spews garbage galore once I telnet to my Arduino at port 80.
Code: Select all
#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() {
  int pos = 0;
  Client client = server.available();
  if (client) {
    while(client.connected()) {
      if (client.available()) {
        int in = client.read();
        Serial.write(in);
      }

    }
    delay(1);
    client.stop();
  }
}
#134138
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.
Code: Select all
*** 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)