[SOLVED!] ENC28J60 on MEGA2560 with Andy's EtherShield 1.6 problem

Hello everyone,

Ok I have searched and searched and cannot find an answer here.

I’m looking for a decent library to use with my nuelectronics-style ENC28J60 board (made by ekitszone). This seems to be a popular board so I’m stumped as to why it’s so hard to find a good library.

I have the ekitszone library working for webserver and ping server only but it is outdated, buggy and lacks outbound connectivity. Andy’s library seems to be aimed at the smaller arduino boards and has additional functionality for outbound but I cannot get his library to work. I have adjusted the enc28j60.cpp and .h and ip_config.h files accordingly with the new pinout but it still does nothing when run.

I’ve been googling for hours and come up with nothing. Can someone either point me in the right direction with how to fix this library or to another library that works well? Thank you in advance!

… found the problem - it’s a bug with Andy’s library…

The file enc28j60.c uses #ifdef USE_RF12 in several places, of particular importance is here:

static void enableChip()
#ifdef USE_RF12
  digitalWrite(enc28j60ControlCs, LOW);
  PORTB &= ~(1<<2);

// Disable ENC28J60 then enable interupts
static void disableChip() {
#ifdef USE_RF12
  digitalWrite(enc28j60ControlCs, HIGH);
  PORTB |= (1<<2);

Except that is defined in ip_config.h … which enc28j60.c does not include.

Adding a #include “ip_config.h” to the top of enc28j60.c and it magically starts working, assuming that the appropriate PIN defines are made to the top of enc28j60.h:

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

#define DEFAULT_ENC28J60_CONTROL_CS     53
#define SPI_SS      53
#define SPI_MOSI		51
#define SPI_MISO		50
#define SPI_SCK			52


// Default CS pin is 10, for the unmodified shield.
// Can be changed in init function to use another pin
// But SPI_SS needs to be setup correctly too
#define DEFAULT_ENC28J60_CONTROL_CS             10
#define SPI_SS                                  10
#define SPI_MOSI				11
#define SPI_MISO				12
#define SPI_SCK					13


Not to keep replying to my own post, but I verified with Andy's latest GIT release and the problem still exists.

Applying the previous 2 modifications fixes the problem, and to get the webserver demo working you need to add the first 3 lines if you have a microsd card on the board:

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

  // Initialise SPI interface

  // initialize enc28j60

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

After that it works like a charm!