problem with ENC28J60 & Ardunio Mega 2560.... help please

hello everybody …

Recently I bought an ENC28J60 Module (HanRun HR91105A 16/02) … the EthernetCard , I download the specfic library of it (EthernetCard.h) .

and then I connecting the ENC28J60 to Arduino Mega 2560 like this:

Arduino 5v to ENC28J60 VCC
Arduino GND to ENC28J60 GND
Arduino Reset to ENC28J60 Reset
Arduino PIN 50 to ENC28J60 SO
Arduino PIN 51 to ENC28J60 SI
Arduino PIN 52 to ENC28J60 SCK
Arduino PIN 53 to ENC28J60 CS

Then the Ethercard is working … the orange led in the ENC28J60 is on… that’s mean the ENC28J60 is working.

after that I used the example backsoon from Ethernetcard examples code :

// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
 
#include <EtherCard.h>

#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)

#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,1,200 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif

// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[500]; // tcp/ip send and receive buffer

const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
  "<head><title>"
    "Service Temporarily Unavailable"
  "</title></head>"
  "<body>"
    "<h3>This service is currently unavailable</h3>"
    "<p><em>"
      "The main server is currently off-line.
"
      "Please try again later."
    "</em></p>"
  "</body>"
"</html>"
;

void setup(){
  Serial.begin(57600);
  Serial.println("\n[backSoon]");
  
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  
}

void loop(){
  // wait for an incoming TCP packet, but ignore its contents
  if (ether.packetLoop(ether.packetReceive())) {
    memcpy_P(ether.tcpOffset(), page, sizeof page);
    ether.httpServerReply(sizeof page - 1);
  }
}

then I open the browser and write the IP : 192.168.1.200 … The webpage doesn’t show… at all
first I though the problem from modem that I used (TD-W8101G) but the setting was fine … :-\

I need your help with this situation … please :’(

help me :confused:

I used 3.3V to power the HanRun ENC28J60 and I connected its reset pin to 3.3V as well. Other than that your wiring looks good.
What output do you get from the Serial monitor?

Pete

I getting from serial monitor this message : backSoon

that’s mean it’s connection right ?! if it’s right … what the problem?!

look at the void setup code :-

void setup(){
  Serial.begin(57600);
  Serial.println("\n[backSoon]");
  
  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");
#if STATIC
  ether.staticSetup(myip, gwip);
#else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
#endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  
}

Yes, I know the setup code. I've used it myself and it works. What you hadn't said was what you were seeing on the serial monitor. If it says only [backSoon] then that's a different kind of problem than if it prints that and the three IP addresses.
And, no, [backSoon] on its own doesn't mean it is connected to anything. It has to print the three (valid) IP addresses before it is ready.

If you are only seeing [backSoon] then it is not getting the required info from the ENC28J60, which can have a whole host of causes.
The most obvious one is that it isn't wired up properly. You appear to have the correct wiring between the ENC28J60 and the Mega except as I noted previously that I used 3.3V instead of 5V and I connected Reset directly to 3.3V instead of to the Mega Reset pin. Try those.
I presume that you have a cable connecting the ENC28J60 to your router. Which kind of router are you using?

Pete

Are you sure that your ENC28J60 board allows 5V? Some boards have a 3v3 regulator so that you can use 5V as the supply. But the one I have (HanRun HR911105A 14/23) does not have a regulator and I power it with 3.3V. You need to check this because 5V could damage the chip.

Pete

Can you post a link to the library? I'm not certain about the ENC28J60, but the w5100 uses D10 for the slave select no matter what Arduino it is connected to. Have you tried connecting the ENC28J60 CS to D10 instead of D53?

edit: If this is the library, then you should either specify the CS pin in the begin call, or it uses D8 as the default. Try D8 as the CS pin.
http://jeelabs.org/pub/docs/ethercard/

I think you nailed it SurferTim.
In the EtherCard library, if you don't specify the CS pin number when calling begin() it defaults to Pin 8.
Try this:

  if (ether.begin(sizeof Ethernet::buffer, mymac,53) == 0)

Pete

I checked the script and I figure out that I forgot to set STATIC to 1 , that disable the dhcp as below:

#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)

also the in the setup code , ether.begin should be (sizeof Ethernet::buffer, mymac, 53) the cs pin in ENC28J60 to D53 in arduino mega.(someone said that should be in the pins D8 but I thank that for arduino uno) as below :

if (ether.begin(sizeof Ethernet::buffer, mymac,53) == 0)

after that , I upload it to arduino mega , then I opened the serial monitor shown this:

backsoon

IP: 192.168.1.200
GW: 192.168.1.1
DNS: 0.0.0.0

The dns was 0... maybe because I hadn't any internet connection in the modem... at all..

maybe that's why doesn't SHOW The webpage.... when I enter IP : 192.168.1.200 in browser.

Can I made webserver by ENC28J60 without internet connection ... with offline network? ...and how :sweat_smile:

ps : My project is Arduino Home Automation ...I want to Controlling led's . servo , whatever by ENC28J60 offline network :cold_sweat:

el_supremo:
Yes, I know the setup code. I've used it myself and it works. What you hadn't said was what you were seeing on the serial monitor. If it says only [backSoon] then that's a different kind of problem than if it prints that and the three IP addresses.
And, no, [backSoon] on its own doesn't mean it is connected to anything. It has to print the three (valid) IP addresses before it is ready.

If you are only seeing [backSoon] then it is not getting the required info from the ENC28J60, which can have a whole host of causes.
The most obvious one is that it isn't wired up properly. You appear to have the correct wiring between the ENC28J60 and the Mega except as I noted previously that I used 3.3V instead of 5V and I connected Reset directly to 3.3V instead of to the Mega Reset pin. Try those.
I presume that you have a cable connecting the ENC28J60 to your router. Which kind of router are you using?

Pete

ENC28J60 (HanRun HR91105A 16/02)… had a pin his name 5v… that’s the Vcc pin… I plug it in 5v

ardiuno mega… because it’s named on the Vcc pin but , I don’t try to plug it in 3v3 … I will try to plug to

3v3 tonight … and I will see what happening to ENC28J60

el_supremo:
Are you sure that your ENC28J60 board allows 5V? Some boards have a 3v3 regulator so that you can use 5V as the supply. But the one I have (HanRun HR911105A 14/23) does not have a regulator and I power it with 3.3V. You need to check this because 5V could damage the chip.

Pete