Ethernet.begin() fails!

Hi,

I have problem in starting ethernet shield.I tested all the codes which I googled with no success. Besides, I connected my shield to PC and read the MAC addreess because I thought maybe wrong MAC address will give the DHCP config error. I also checked my router and saw that DHCP was already enabled. I have no SD card and these LEDs are on:
PWR(red)
LINK(y)
100M(y)
FULLD(y)

sometime RX led blinks in other examples included in Arduino.
I always get this error:
Failed to configure Ethernet using DHCP
which means I can not initialize Ethernet shield using Ethernet.begin() function.
What should I do?
The code I test:

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  
  0x00, 0x06, 0x4F, 0x0D, 0xAC, 0xA9 };

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // start the serial library:
  Serial.begin(9600);
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
      ;
  }
  // print your local IP address:
  Serial.println(Ethernet.localIP());

}

void loop() {
}

Try this test sketch. It will check the w5100 and SPI bus. If it shows 192.168.2.2, then it is working ok. If it shows anything else, like 0.0.0.0, then you have a hardware problem with the SPI or the w5100.

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

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,2,2);

void setup() {
  Serial.begin(9600);

  // disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.println("Starting w5100");
  Ethernet.begin(mac,ip);

  Serial.println(Ethernet.localIP());
}

void loop() {
}

Check the ICSP connection closely. That is how the SPI data lines connect to the shield on the newer model shields.

Thank you for your help.
This is what I get in the serial monitor:
Starting w5100
255.255.255.255

This is the connection I use:
Top view of the Ethernet shield board:

GND RESET
MOSI SCK
VCC MISO

If it did not return 192.168.2.2, you have a hardware problem. :frowning:

Which ethernet shield are you using? A link to that product would be helpful.

I do not have a link for my shield amd also no MAC add printed on it.
For yours, Is MOSI of Arduino is connected to MISO of rethernet shield and vice versa?

I don't understand. If it is a shield, it should plug into the Arduino.

ereihani:
I do not have a link for my shield amd also no MAC add printed on it.
For yours, Is MOSI of Arduino is connected to MISO of rethernet shield and vice versa?

NO!! The MOSI on the Arduino connects to MOSI on the shield. Master Out Slave In
Same with MISO Master In Slave Out

Maybe my Arduino does not work!
What is the pinout of ICSP in Ethernet shield looking from top of the board?
Is it like this:

Here is the Arduino page on the ethernet shield.

It has a schematic that shows the pinouts.

Why are you not just plugging it in to the Arduino?

I have plugged it but still the same 255.255.255.255 appears. I think I should connect by wire.
OOps! I found the the problem! Apart from the SPI pins, I should have also connected SS pin(#10 ).

try using the Ethenetcard library

melvinlo:
try using the Ethenetcard library

http://www.instructables.com/id/Add-Ethernet-to-any-Arduino-project-for-less-than-/

That would be a good idea if the OP used an ethernet card with a ENC28j60 instead of a w5100 ethernet controller.

SurferTim:

try this one and tell me if it gives you an error

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

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(169, 254, 247, 62);//My computer ethernet ip adress 

void setup() {
  Serial.begin(9600);

  // disable SD card if one in the slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Serial.println("Starting w5100");
  Ethernet.begin(mac,ip);
  while(!Ethernet.begin(mac))
  {
    Serial.println("eroooorr");
  }

  Serial.println(Ethernet.localIP());
}

void loop() {
}

Check the ICSP connection closely. That is how the SPI data lines connect to the shield on the newer model shields.