Problem with W5200 ethernet shield on DUE (R3)

Hi,

My W5200 (v2.1) Ethernet shield from seedstudio works fine on an UNO but it won’t compile for the DUE (R3)
Anybody got this to work?
Code is the chatserver tutorial that comes with the W5200
I followed the instruction from here Ethernet Shield V2.0 | Seeed Studio Wiki
And it works ok for the uno, but not for the due.

Help appreciated!

Errors (log) below:

Arduino: 1.5.6-r2 (Windows 7), Board: "Arduino Due (Programming Port)"

Using library EthernetV2_0 in folder: C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0 (legacy)
Using library SPI in folder: C:\Program Files (x86)\Arduino\hardware\arduino\sam\libraries\SPI (legacy)

C:\Program Files (x86)\Arduino/hardware/tools/g++arm_none_eabi/bin/arm-none-eabi-g++ -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=156 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E_ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due" -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\system/libsam -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\system/CMSIS/CMSIS/Include/ -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\system/CMSIS/Device/ATMEL/ -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\variants\arduino_due_x -IC:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0 -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\libraries\SPI C:\Users\xxxxx\AppData\Local\Temp\build1674528417543249285.tmp\bjorn_ChatServer_uno.cpp -o C:\Users\xxxxx\AppData\Local\Temp\build1674528417543249285.tmp\bjorn_ChatServer_uno.cpp.o
C:\Program Files (x86)\Arduino/hardware/tools/g++arm_none_eabi/bin/arm-none-eabi-g++ -c -g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=156 -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM -D__SAM3X8E_ -mthumb -DUSB_VID=0x2341 -DUSB_PID=0x003e -DUSBCON -DUSB_MANUFACTURER="Unknown" -DUSB_PRODUCT="Arduino Due" -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\system/libsam -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\system/CMSIS/CMSIS/Include/ -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\system/CMSIS/Device/ATMEL/ -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\variants\arduino_due_x -IC:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0 -IC:\Program Files (x86)\Arduino\hardware\arduino\sam\libraries\SPI -IC:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\utility C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\DhcpV2_0.cpp -o C:\Users\xxxxx\AppData\Local\Temp\build1674528417543249285.tmp\EthernetV2_0\DhcpV2_0.cpp.o
In file included from C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\DhcpV2_0.cpp:4:
C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\utility/w5200.h: In static member function 'static void W5100Class::initSS()':
C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\utility/w5200.h:357: error: 'DDRB' was not declared in this scope
C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\utility/w5200.h:357: error: '_BV' was not declared in this scope
C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\utility/w5200.h: In static member function 'static void W5100Class::setSS()':
C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\utility/w5200.h:358: error: 'PORTB' was not declared in this scope
C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\utility/w5200.h:358: error: '_BV' was not declared in this scope
C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\utility/w5200.h: In static member function 'static void W5100Class::resetSS()':
C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\utility/w5200.h:359: error: 'PORTB' was not declared in this scope
C:\Users\xxxxx\Documents\Arduino\libraries\EthernetV2_0\utility/w5200.h:359: error: '_BV' was not declared in this scope

code:
#include <DhcpV2_0.h>
#include <DnsV2_0.h>
#include <EthernetClientV2_0.h>
#include <EthernetServerV2_0.h>
#include <EthernetUdpV2_0.h>
#include <EthernetV2_0.h>
#include <utilV2_0.h>

/*
Chat Server

A simple server that distributes any incoming messages to all
connected clients. To use telnet to your device's IP address and type.
You can see the client's input in the serial monitor as well.
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

*/

#include <SPI.h>
//#include <EthernetV2_0.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//IPAddress ip(192,168,1, 177);
//IPAddress gateway(192,168,1, 1);
//IPAddress subnet(255, 255, 0, 0);

IPAddress ip(172,20,1, 10);
IPAddress gateway(172,20,1, 1);
IPAddress subnet(255, 255, 0, 0);

// telnet defaults to port 23
EthernetServer server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously
#define W5200_CS 10
#define SDCARD_CS 4

void setup()
{
pinMode(SDCARD_CS,OUTPUT);
digitalWrite(SDCARD_CS,HIGH);//Deselect the SD card
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
server.begin();
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.print("Chat server address:");
Serial.println(Ethernet.localIP());
}

void loop()
{
while (true)
{
// wait for a new client:
EthernetClient client = server.available();

// when the client sends the first byte, say hello:
if (client)
{
if (!alreadyConnected)
{
// clead out the input buffer:
client.flush();
Serial.println("We have a new client");
client.println("Hello, client!");
alreadyConnected = true;
}

if (client.available() > 0)
{
// read the bytes incoming from the client:
char thisChar = client.read();
// echo the bytes back to the client:
server.write(thisChar);
// echo the bytes to the server as well:
Serial.write(thisChar);

if (thisChar == 'Q')
alreadyConnected = false;
}
}
}
}

I think it would be with this section of code in w5200.h.

private:
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  inline static void initSS()    { DDRB  |=  _BV(4); };
  inline static void setSS()     { PORTB &= ~_BV(4); };
  inline static void resetSS()   { PORTB |=  _BV(4); };
#elif defined(__AVR_ATmega32U4__)
  inline static void initSS()    { DDRB  |=  _BV(6); };
  inline static void setSS()     { PORTB &= ~_BV(6); };
  inline static void resetSS()   { PORTB |=  _BV(6); }; 
#elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB162__)
  inline static void initSS()    { DDRB  |=  _BV(0); };
  inline static void setSS()     { PORTB &= ~_BV(0); };
  inline static void resetSS()   { PORTB |=  _BV(0); }; 
#else
  inline static void initSS()    { DDRB  |=  _BV(2); };
  inline static void setSS()     { PORTB &= ~_BV(2); };
  inline static void resetSS()   { PORTB |=  _BV(2); };
#endif

It probably needs the port assignment for the Due added. I don't have a Due to play with, so I can't test anything.

I do have code that replaces this section of code to use different digital pins for the slave select, but it is in a different computer that will take a while to get to.

edit: You can see the files I changed for the w5100 in this post.
http://forum.arduino.cc/index.php?topic=217423.msg1881620#msg1881620
Requires changes in w5100.h and w5100.cpp.

Thanks SurferTim, i'll have a look at it...

Just out of curiosity:
Does the ethernet library included with the IDE compile ok?
Does the ethernet library with my file modifications above compile ok?

edit: If the second is true, I have downloaded the files for the w5200 and can try to modify them for you. The w5200 IC has some real advantages over the w5100. It would be an improvement to have code for that IC.

edit2: After a bit of experimenting, I found the Due uses a different set of w5100.h and w5100.cpp files. Even if I could get it to compile, I wouldn't be able to run it to insure it worked. The w5100 files are modified to work with the Atmel SAM3X8E ARM Cortex-M3 CPU.

In IDE v1.5.x,
the AVR w5100 files are in "libraries/Ethernet/arch/avr/utility/".
the Due w5100 files are in "libraries/Ethernet/arch/sam/utility/".

hi,

libs compiled ok.

in the meantime i bought the common Ethernet shield (A000072) (without poe) hoping that would work (saving me the time)
It seems it works partly on the Due R3, it looks like it has trouble sending data, receiving (from pc -> arduino) works ok (or i made a mistake somewhere (?).
the udp sample works both ways which is fine for me.

so i leave it at that for now, if i have the time later, i'll test more but since i have a lot more to do...
thanks for your help.