ENC28J60 + Mega2650 - Resolved

Hi All,

I have been working with the ethernet module for 2 weeks and am still unable to get any connectivity to it. Any pointers would be awesome

Hardware in use:

Mega2560 R2
Geeetech.com Ethernet based on ENC28J60 chipset. http://www.geeetech.com/arduino-enc28j60-ethernet-module-p-263.html
Library: http://www.nuelectronics.com/download/projects/etherShield.zip

Pin connections:

Mega Ethernet
50 SO
51 SI
52 SCK
53 CS ( SS ? )

Example code (one of a bunch I have 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,16,15};
// how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX

#define BUFFER_SIZE 250
unsigned char buf[BUFFER_SIZE+1];

uint16_t plen;

EtherShield es=EtherShield();


void setup(){

 
 
  /*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=green 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){
       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);
   		    }
      }
 
  }  
}

I don't know about the ENC28J60 and that library, but most ethernet library code uses the SS pin from the Uno, which is digital pin 10.

Just a thought...

Have the same lack of response with that too :disappointed_relieved:

Thanks for looking.

My laptop gets a 10Mbit hardware connection but no pkts are rx by the laptop.

It's not going to work without modification.

You can see this right in enc28j60.c, which clearly does not match your setup

#define ENC28J60_CONTROL_CS     10
#define SPI_MOSI				11
#define SPI_MISO				12
#define SPI_SCK					13

Anyway, the state of the art ENC28J60 library is EtherCard, although that will require modification to work with Mega also.

thanx for the reply Manic,

Are you saying that if I adjust those values to match the pins for the mega (50-52) or (50-53) it should work?

A few things about Arduino irritate me including the forward/backward compatibility issues, but this isn't the place to grumble about things.

chromus:
Are you saying that if I adjust those values to match the pins for the mega (50-52) or (50-53) it should work?

Rather I'm saying if you don't change it, it WON'T work :grin: Certainly worth trying, though there may be something else too.

chromus:
A few things about Arduino irritate me including the forward/backward compatibility issues, but this isn't the place to grumble about things.

This incompatibility isn't Arduino's fault, it's all on the EtherShield library. Most people don't write their libraries to be Mega-compatible. But hey, it's free code.

I adjusted the library as per the suggestion, reuploaded and still nothing.

#define ENC28J60_CONTROL_CS 53
#define SPI_MOSI 51
#define SPI_MISO 50
#define SPI_SCK 52

Anymore ideas would be awesome

What would be the pin numbers if I used the ICSP header instead?

I have spent the whole weekend futzing with this and still now joy.

I tried a suggestion from another thread about using pin 10 instead of 53 (with associated library update) and still no joy.

Any1 else have any suggestions?

Check that your wiring is as follows:

Atmega pin ENC28J60 module pin
50 4
51 5
52 6
53 7

The pins on the ENC are rated 3.3v but are 5v tolerant. However the voltage for powering the module is 3.3 volts.

Check you have a 3.3 volts on pin 9 and gnd of the power supply and Mega to pin 10 of module.

The Geetech manual shows the module running off VCC from the Arduino. THis would be fine if they had a regulator on the ENC module but the schematic for it shows no such voltage reduction. The Microchip ENC28J60 datasheet states that the ENC is a 3.3 volt device. Unless your Arduino is has A VCC of 3.3v you will damage the chip connecting pin 9 directly to VCC.

The Nuelectronics ENC28J60 shield schematic clearly shows the 3.3v onboard regulator and signal level shifters. Yours does not have these niceties but will still work if care is taken.

I can't recall if there is a 3.3v output on the Mega but do not use this if there is as it is usually only rated to 50 ma(from memory). Typically network modules pull ~100-250 ma.

Try connecting the module and PC to a ethernet hub/switch (instead of directly to each other) in case the crossover detection isn't working.

Also try cutting and pasting the code from the Geeetech "Manual source code.pdf" for a test sketch:

This is different to the Ping test code in the:

http://www.nuelectronics.com/download/projects/etherShield.zip

Thanks for your help lemming. The issue is now fixed

The 3.3v out on the mega seems happy supplying the constant 75ma that my multimeter says the module is drawing.

The resolution was in the end connecting the VCC to the 3.3v, I had mis-understood the description and had been working on the assumption that the power input was 5v tolerant as well as the data pins.

So to finalise this in a nutshell:

Fix the ENC28J60.c file as follows:

#define ENC28J60_CONTROL_CS    53
#define SPI_MOSI            51
#define SPI_MISO            50
#define SPI_SCK                           52

Connect The pins as follows:

Atmega pin ENC28J60 module pin
50 4
51 5
52 6
53 7
3.3v 9
Grnd 10