Ethershield v1.1 not working

I bought one of those cheapo ENC28J60 shields, since there seems to be a reasonable amount of support for them now. Not having much luck though. Uploading, no errors occur and the 2 LEDs on the jack blink twice as if to say 'I'm ok'. Plugging the network cable in, those same lights go from off to on solid. No port lights up on the hub. The router doesn't see it. It can't be pinged. I've used the libraries from Nuelectronics, Andy's Life, and the vendor. All fail to work equally.
Am I looking at a pooched board?

Hi,

Could you post your sketch so we can have a look? I've used this successfully quite a few times and own up to being responsible for an updated library...

thanks

Andy.

Thanks for the response. I've just been trying the examples at this point, maybe changing the IP if necessary. The one I currently have loaded follows, in which I have changed nothing:

#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};
static char baseurl[]="http://192.168.1.15/";
static uint16_t mywwwport =80; // listen port for tcp/www (max range 1-254)
// or on a different port:
//static char baseurl[]="http://10.0.0.24:88/";
//static uint16_t mywwwport =88; // listen port for tcp/www (max range 1-254)
//

#define BUFFER_SIZE 500
static uint8_t buf[BUFFER_SIZE+1];
#define STR_BUFFER_SIZE 22
static char strbuf[STR_BUFFER_SIZE+1];

EtherShield es=EtherShield();

// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf);
int8_t analyse_cmd(char *str);
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=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(){
uint16_t plen, dat_p;
int8_t cmd;

plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

/*plen will ne 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);
return;
}

// check if ip packets are for us:
if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){
return;
}

if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
es.ES_make_echo_reply_from_request(buf,plen);
return;
}

// tcp port www start, compare only the lower byte
if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==mywwwport){
if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V){
es.ES_make_tcp_synack_from_syn(buf); // make_tcp_synack_from_syn does already send the syn,ack
return;
}
if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){
es.ES_init_len_info(buf); // init some data structures
dat_p=es.ES_get_tcp_data_pointer();
if (dat_p==0){ // we can possibly have no data, just ack:
if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){
es.ES_make_tcp_ack_from_any(buf);
}
return;
}
if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
// head, post and other methods for possible status codes see:
// HTTP/1.1: Status Code Definitions
plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n

200 OK

"));
goto SENDTCP;
}
if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){
plen=print_webpage(buf);
goto SENDTCP;
}
cmd=analyse_cmd((char *)&(buf[dat_p+5]));
if (cmd==1){
plen=print_webpage(buf);
}
SENDTCP: es.ES_make_tcp_ack_from_any(buf); // send ack for http get
es.ES_make_tcp_ack_with_data(buf,plen); // send data
}
}
}

}
// The returned value is stored in the global var strbuf
uint8_t find_key_val(char *str,char *key)
{
uint8_t found=0;
uint8_t i=0;
char *kp;
kp=key;
while(*str && *str!=' ' && found==0){
if (*str == *kp){
kp++;
if (*kp == '\0'){
str++;
kp=key;
if (*str == '='){
found=1;
}
}
}else{
kp=key;
}
str++;
}
if (found==1){
// copy the value to a buffer and terminate it with '\0'
while(*str && *str!=' ' && *str!='&' && i<STR_BUFFER_SIZE){
strbuf_=*str;_

  • i++;*
  • str++;*
  • }*
    _ strbuf*='\0';_
    _
    }_
    _
    return(found);_
    _
    }_
    int8_t analyse_cmd(char str)
    _
    {
    _
    * int8_t r=-1;*

* if (find_key_val(str,"cmd")){
_ if (strbuf < 0x3a && strbuf > 0x2f){_
_
// is a ASCII number, return it
_
_ r=(strbuf-0x30);_
_
}
_
* }*
* return r;*
}
uint16_t print_webpage(uint8_t buf)
_
{_
uint16_t plen;
plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

Welcome to Arduino Ethernet Shield V1.0

"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("

_

<font color="blue">-- Put your ARDUINO online -- "));_
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
Control digital outputs "));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
Read digital analog inputs HERE "));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
_

") );_
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("
V1.0 <a href="http://www.nuelectronics.com">www.nuelectronics.com"));*

* return(plen);*
}

Hi,

Just a thought, do you have your ethernet cable connected when you start the arduino or reset it? Also, is it a straight through cable not a cross-over cable? It should be straight unless your hub is able to be selectable.

Make sure the IP address you setup is one that is valid on your network, a 10.x.x.x address on your PC and a 192.168.x.x on the arduino wont work.

Also, make sure you are not mixing libraries up, delete the libraries/etherShield directory and extract a fresh copy from one of the zip files.

Then try the examples that comes with that zip file.

Also, when posting code, you may like to use the code tags on the post editor as it will help preserve the formatting and stopp special characters being changed.

Hope this helps

Cheers

Andy
:slight_smile:

I have tried with the cable in and out while connecting dc and resetting.
Straight through. I changed the IP to match my 192 in examples where necessary, and left it alone where it was already suitable. I've deleted the older library each time, and tried the specific example with each.
Overlooked the code posting option. :-[
I'm going to borrow an alternate Arduino tonight. If it works, mine is bad; if it doesn't, then it's code or shield. Although I bought this Arduino about a year ago, this is its first time out of the bag. I've been using barebones and iduinos, not form-factored for shields.
Thanks for your interest.
Barry

Result. With all combinations of ports, cables, libraries, compilation under MS and Linux with 0017 and 0018, with different shields and duinos, no work. Then on a whim I plugged into a switch downstairs and all was well. It seems my 3com tp800 just won't play, but an HP Procurve is happy to.