troubleshoot an enc28j60 ethernet breakout board

I have been trying to learn how to use an enc28j60 Ethernet board like this one: http://www.ebay.com/itm/ENC28J60-Ethernet-LAN-Module-for-UNO-Duemilano-MEGA-AVR-LPC-STM32-Experiment-/280885084858?pt=LH_DefaultDomain_0&hash=item41660e42ba. Unfortunately, I haven't been successful with any of the half-dozen example sketches. I have tried with an UNO as well as a Mega, changing the pin definitions as needed in the enc28j60.c file. The power led is on, the sketch uploads fine, but nothing else- no blinking lights on the module and definitely no webpage on the local lan. I am beginning to think that the module is defective. Anyone know of away to "see" if the Arduino is talking to the board and if the board is responding? Where else could I have gone wrong? I am 95% sure of my connections as I have an SD card reader that uses the same ICSP connections and I have no problems with that.

You don't provide a wiring diagram or the code you're using with this module. Both is necessary to enable us to help you. Also specify everything you have connected to your Arduino additionally.

Do you disable the SD card (by pulling SS high) while accessing the Ethernet module?

The basic wiring scheme i used can be found here :http://www.geeetech.com/Documents/ENC28J60%20Manual%20Source%20Code.pdf For the uno: CS --> 10 MOSI --> 11 MISO --> 12 SCK --> 13 For the Mega: CS -->53 SI -->50 SO -->51 SCK -->52

With VCC connected to 3.3v and grounds connected The datasheet can be found here: http://ww1.microchip.com/downloads/en/DeviceDoc/39662c.pdf

Nothing else is connected to the arduino, just the Ethernet module. The SD module is a separate unit and not connected at the same time, although i did try both just for kicks (using separate ss pins). the code i am using is the standard examples that come with the etherShield 1.1v library which can be found here: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1280420867/all. nothing in the code was changed, except for the pin definitions i already mentioned for the mega.

here is one example i tried:

#include "etherShield.h"

// please modify the following two lines. mac and ip have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24}; 
static uint8_t myip[4] = {192,168,1,15};

#define BUFFER_SIZE 250
static uint8_t buf[BUFFER_SIZE+1];

uint16_t plen;

EtherShield es=EtherShield();


void setup(){
  
   /* Disable SD card */
   pinMode(4, OUTPUT);
   digitalWrite(4, HIGH);
   
       /*initialize enc28j60*/
     es.ES_enc28j60Init(mymac);
        es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
       delay(10);
        
    /* Magjack leds configuration, see enc28j60 datasheet, page 11 */
    // LEDA=greed LEDB=yellow
    //
    // 0x880 is PHLCON LEDB=on, LEDA=on
    // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
    es.ES_enc28j60PhyWrite(PHLCON,0x880);
    delay(500);
    //
    // 0x990 is PHLCON LEDB=off, LEDA=off
    // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
    es.ES_enc28j60PhyWrite(PHLCON,0x990);
    delay(500);
    //
    // 0x880 is PHLCON LEDB=on, LEDA=on
    // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
    es.ES_enc28j60PhyWrite(PHLCON,0x880);
    delay(500);
    //
    // 0x990 is PHLCON LEDB=off, LEDA=off
    // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
    es.ES_enc28j60PhyWrite(PHLCON,0x990);
    delay(500);
    //
  // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
  // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
  es.ES_enc28j60PhyWrite(PHLCON,0x476);
    delay(100);
        
  //init the ethernet/ip layer:
  es.ES_init_ip_arp_udp_tcp(mymac,myip,80);


}

void loop(){

    plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

      /*plen will be unequal to zero if there is a valid packet (without crc error) */
    if(plen!=0){
            // arp is broadcast if unknown but a host may also
      // verify the mac address by sending it to 
      // a unicast address.
      if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){
         es.ES_make_arp_answer_from_request(buf);
      }
      // check if ip packets (icmp or udp) are for us:
      if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)!=0){
         if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
                // a ping packet, let's send pong
            es.ES_make_echo_reply_from_request(buf,plen);
               }
      }
    }  
}

That sketch does not serve a web page, it only answers ARP and ICMP ping requests. So to check if that works you have to run the command "ping 192.168.1.15" from your command line.

Before that remove all calls to enc28j60PhyWrite() from your sketch as that may "confuse" the chip.

Why do you change the clkout? This is done in the init routine already.

If you still don't get any LED activity, you should check the cabling, does the other party (switch, router, etc.) have the link up?

oh thank you! i did not realize i had to run the ping command. updated Code:

#include "etherShield.h"

// please modify the following two lines. mac and ip have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static uint8_t mymac[6] = {
  0x54,0x55,0x58,0x10,0x00,0x24}; 
static uint8_t myip[4] = {
  192,168,1,15};

#define BUFFER_SIZE 250
static uint8_t buf[BUFFER_SIZE+1];

uint16_t plen;

EtherShield es=EtherShield();


void setup(){

  /* Disable SD card */
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);

  /*initialize enc28j60*/
  es.ES_enc28j60Init(mymac);



  //init the ethernet/ip layer:
  es.ES_init_ip_arp_udp_tcp(mymac,myip,80);


}

void loop(){

  plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

  /*plen will be unequal to zero if there is a valid packet (without crc error) */
  if(plen!=0){
    // arp is broadcast if unknown but a host may also
    // verify the mac address by sending it to 
    // a unicast address.
    if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){
      es.ES_make_arp_answer_from_request(buf);
    }
    // check if ip packets (icmp or udp) are for us:
    if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)!=0){
      if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
        // a ping packet, let's send pong
        es.ES_make_echo_reply_from_request(buf,plen);
      }
    }
  }  
}

this is the message i get in CMD:

Pinging 192.168.1.15 with 32 bytes of data: Reply from 192.168.1.114: Destination host unreachable. Reply from 192.168.1.114: Destination host unreachable. Reply from 192.168.1.114: Destination host unreachable. Reply from 192.168.1.114: Destination host unreachable.

Ping statistics for 192.168.1.15: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

please explain how

enc28j60PhyWrite() .... may "confuse" the chip.

What does that call do?

The code shown was used as I found it; whoever wrote the code made the changes to clkout. Should that change not be included?

There is no sign of a link up at the switch between the switch and ethernet board. The switch does have active connections to a computer, NAS, and router. I have tried two different cables both of which worked with the computer.

The result you got from the ping command shows that something is not yet working as desired.

Also the LED should at least flicker a second or two after you pressed the reset button.

Have you tried insert Serial.println() statements in your sketch to see where it stops? That's what I would have done next.

Do you have an oscilloscope to see what's going on between the Arduino and the board?

yes the onboard led attached to pin13 flickers brightly 2-3 times after a reset and then remains very dimly lit. Using Serial.println(), it appears that the arduino runs the setup, then continuously checks to see if a packet has arrived, which never happens because none of the if statements are ever executed, even if I ping the ip. No i do not have access to an o-scope, is there another way to see if the arduino is actually communicating with the ethernet module?

No i do not have access to an o-scope, is there another way to see if the arduino is actually communicating with the ethernet module?

A logic analyser would have been my next question but it's unlikely that you own one without a scope.

If the led flickers a few times, this probably means the board is communicating with the Arduino. But if this is the case, it's very likely that you have a cabling problem. Does other end of the network cable (Switch, Router, etc.) have the link LED on?

In the initialisation routine the two LEDs are switch on and off again and are then set to show the link status/traffic. This means if the link level is up (that's handled in hardware in almost every case) at least one LED should light up. How do you connect the device and to what other party?

So after several weeks of this ethernet board sitting idly in the back corner of my desk, I picked it up and looked it over carefully. Lo and behold, one the surface mount resistors was askew about 45 degrees. A quick soldering job later, and the board works great now!

which library u using and what are the connections?? coz ethershield library doesnot work with mine while ethercard does :O

I'm pretty sure I'm using the etherShield Library. Although I did download and install at least three different libraries and all of them work, i didn't try the ethercard one. my connections are based upon the definitions given in the enc28j60.c file:

define ENC28J60_CONTROL_CS 10 (cs)

define SPI_MOSI 11 (si)

define SPI_MISO 12 (so)

define SPI_SCK 13 (sck)

  • which are standard connections for SPI on an Uno. Also need to connect: VCC-->3.3V , reset-->reset, and grounds

could you please send the etherShield library which works for you? :) coz i also have tried many and they dont work

This is where i found the etherShield library: Trollmaker.com