ENC28J60 problems

Hello to everybody,

I just bought an ethernet shield without knowing the big difference between the ENC28J60 series and the WIZ...

The point is that, so far, I have not found an example easy enough for me to addapt to my project. I just would need to make a http request to a php script I've programmed, i.e. the arduino just has to work as a webclient, and receive a char string. That's all.

Could you please give me any hint or example that I could use?

Thank you.

http://jeelabs.net/projects/cafe/wiki/EtherCard

getStaticIP example should do the job.

Hi there,

Thanks for the info. I tried that library, and following the serial monitor, I can see it crashes almost on the very first line.

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");

Serial.println("checkpoint charly"); --> my control line

It doesnt even show the control I added.

It maybe has to do with the fact that my card is not a EtherCard, but an Arduino Shield v1.1

Any solution? Thanks a lot in advance.

It maybe has to do with the fact that my card is not a EtherCard, but an Arduino Shield v1.1

Post a link to the device you really have.

It's this one.

The cheapest I found actually. Arduino Ethernet v1.1

Had I known there are these differences, I would've bought the "official" one.

Thanks.

Post a link to the device you really have.

is not what you did. A picture snipped from an ebay ad is not the same as a link.

What numbers/names are on the chips on your board?

The chip on the centre: ENC28J60 /SS then a M logo and: 1030CG5

The small one on the right side: 74HG1080

And an "overview" pic:

I hope it's described well enough.

It maybe has to do with the fact that my card is not a EtherCard, but an Arduino Shield v1.1

It does not appear that the library at the jeelabs site is for the ENC28J60 chip.

Maybe the best thing to do is look at the below search to see if you can find some working code that has been posted.

http://www.google.com/search?q=ENC28J60+site%3Ahttp%3A%2F%2Farduino.cc%2Fforum%2Findex.php&hl=en&num=100&lr=&ft=i&cr=&safe=images

zoomkat:
Maybe the best thing to do is look at the below search to see if you can find some working code that has been posted.

ENC28J60 site:http://arduino.cc/forum/index.php - Google Search

Ok, thanks... if I opened this thread it's coz I didn't find it by myself... i'll keep on it :wink:

PaulS:

It maybe has to do with the fact that my card is not a EtherCard, but an Arduino Shield v1.1

It does not appear that the library at the jeelabs site is for the ENC28J60 chip.

This is what I was told...

PaulS:

It maybe has to do with the fact that my card is not a EtherCard, but an Arduino Shield v1.1

It does not appear that the library at the jeelabs site is for the ENC28J60 chip.

Why do you say that? It very much is for the ENC28J60. I use it all the time on that chip.

maniacbug:

PaulS:

It maybe has to do with the fact that my card is not a EtherCard, but an Arduino Shield v1.1

It does not appear that the library at the jeelabs site is for the ENC28J60 chip.

Why do you say that? It very much is for the ENC28J60. I use it all the time on that chip.

I think you're right, but the board is also important... that library you recommended me is not gonna work on my board. Or i'm just not able to.

Hi ikaros, I don't know if you resolved the http request.
During the last week I read a lot about that (enc28j60 and wiznet5xxx).
I'm working with enc28j60 with thiseldo's library.
Check this link: http://blog.thiseldo.co.uk/?tag=enc28j60
the last version: http://blog.thiseldo.co.uk/?p=504
Also I could see a big different about software code when you are preparing a little and clear called request or setup a server. The wiznet library (standard in arduino) is better than enc28j60's libraries.
Anyway I was trying to do a little get request mixing with DHCP feature.
I'm posted the code:
(remember install the last version library)

/* INIT LIBRARY REGION *******************************************************************************/
#include <EtherShield.h>

/* END LIBRARY REGION ********************************************************************************/

/* INIT VARIABLES DECLARATION REGION *****************************************************************/

// count the package received
int packageNumber = 0;

static uint8_t mymac[6] = { 
  0x54,0x55,0x58,0x10,0x00,0x25}; 

static uint8_t myip[4] = {
  0,0,0,0 };
static uint8_t mynetmask[4] = {  
  0,0,0,0 };

static uint8_t gwip[4] = { 
  0,0,0,0};

static uint8_t dnsip[4] = { 
  0,0,0,0 };
static uint8_t dhcpsvrip[4] = { 
  0,0,0,0 };

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

EtherShield es = EtherShield();

#define HOSTNAME "arduino.cc"
#define WEBSERVER_VHOST "arduino.cc"

// sub-path http
#define HTTPPATH "/en/Tutorial/StringAppendOperator"

static int8_t dns_state=DNS_STATE_INIT;

/* FINISH VARIABLES DECLARATION REGION ***********************************************************/

/* INIT FUNCTIONS REGION *************************************************************************/
void printNetworkSettings()
{
  // Display the results:
  Serial.print( "My IP: " );
  printIP( myip );
  Serial.println();

  Serial.print( "Netmask: " );
  printIP( mynetmask );
  Serial.println();

  Serial.print( "DNS IP: " );
  printIP( dnsip );
  Serial.println();

  Serial.print( "GW IP: " );
  printIP( gwip );
  Serial.println();

}

void printMacAddress()
{
  for( int i=0; i<6; i++ ) {
    Serial.print( mymac[i], HEX );
    Serial.print( i < 5 ? ":" : "" );
  }
  Serial.println();
}

// Output a ip address from buffer
void printIP( uint8_t *buf ) {
  for( int i = 0; i < 4; i++ ) {
    Serial.print( buf[i], DEC );
    if( i<3 )
      Serial.print( "." );
  }
}

// Is executed when a package arrives
void browserresult_callback(uint8_t statuscode,uint16_t datapos, uint16_t dataEnd)
{
  Serial.println();
  Serial.print(packageNumber);
  Serial.println(". ------- READING PACKAGE ------------------------------------- ");
  Serial.println();

  int posInit = 0;

  char* text = (char*)&buf[datapos];

  while (posInit < dataEnd)
  {
    Serial.print(text[posInit]);
    posInit++;
  }

  Serial.println();
  Serial.println(" ------ FINISH PACKAGE---------------------------------------------- ");
  Serial.println();

  packageNumber++;
}

/* FINISH FUNCTIONS *******************************************************************************/


void setup() {

  Serial.begin(9600);
  Serial.println();
  Serial.println("DHCP WEB Client test");
  Serial.println();

  Serial.println("Mac Address:");
  printMacAddress();
  Serial.println();

  // Initialise SPI interface
  Serial.println("Init SPI");
  es.ES_enc28j60SpiInit();
  Serial.println();

  // initialize enc28j60 
  Serial.println("Init ENC28J60");
  es.ES_enc28j60Init(mymac);
  Serial.println();

  Serial.println("Init done");
  Serial.println();

  Serial.print( "ENC28J60 version " );
  Serial.println( es.ES_enc28j60Revision(), HEX);
  Serial.println();

  if( es.ES_enc28j60Revision() <= 0 ) {
    Serial.println( "FAILED TO ACCESS ENC28J60 (check version)");
    Serial.println( "The program was canceled.");

    while(1);    // Just loop here
  }

  Serial.println("Requesting IP Address");

  // Get IP Address details
  if( es.allocateIPAddress(buf, BUFFER_SIZE, mymac, 80, myip, mynetmask, gwip, dhcpsvrip, dnsip ) > 0 ) 
  {
    Serial.println("Dinamic IP address process successful");  
    printNetworkSettings();
    Serial.println();
  } 
  else {
    Serial.println("Failed to get IP address");
    Serial.println( "The program was canceled.");

    while(1);    // Just loop here
  }

}


void loop()
{
  uint16_t dat_p;
  int plen = 0;

  // Perform DNS Lookup for host name
  if( es.resolveHostname(buf, BUFFER_SIZE,(uint8_t*)WEBSERVER_VHOST ) > 0 ) {
    Serial.println("Hostname resolved");
    Serial.println();

    Serial.println("Processing Get request to:");
    Serial.print(HOSTNAME);
    Serial.println(HTTPPATH);
    Serial.println();
    
    // wait 5 sec. for checking the serial's messages
    delay(5000);
    
    es.ES_client_browse_url(PSTR(HTTPPATH), NULL, PSTR(HOSTNAME), &browserresult_callback);

    while(1) {

      // wait for a tcp packet - calling this routine powers the sending and receiving of data
      plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);
      dat_p = es.ES_packetloop_icmp_tcp(buf, plen);
    }
  } 
  else {
    Serial.println("Failed to resolve hostname");
  }

}

Good luck with your project ! tell me more about that.

Hi ikaros!

I have exactly the same shield and it is working fine with EtherCard drivers from GitHub - njh/EtherCard: EtherCard is an IPv4 driver for the ENC28J60 chip, compatible with Arduino IDE
Just edit enc28j60.cpp, find code:

#define SELECT_BIT  0   // 0 = B0 = pin 8, 2 = B2 = pin 10 on ATmega328

and change it from 0 to 2

If you plan to use more devices on SPI interface, then this shield needs small rework (cut 2 traces, make 2 new and replace 74HC1080).

Hello,

I have exactly the same problem that ikaros posted on Oct 12, 2011. My shield is the same, and I am using it with a Duemilanove atmega328

I searched for the code mentioned by direk (SELECT_BIT), but in the actual version there is no #define

At the line 254 there is this line

static byte selectBit;  // 0 = B0 = pin 8, 1 = B1 = pin 9, 2 = B2 = pin 10

Any suggestions ?

I solved the problem.

First, I found a version with the #define SELECT_BIT, but the skecthes does not compile.

Looking carefuly at the last version, I tried to set csPin = 10 at the begining of the inialize function, and it worked !

All the examples compile and run perfectly