Arduino SPI Ethernet interfacing problems

Hello Everybody,

This is my first post after some days of readings on this usefull forum;
I need help to interface my arduino 2009 and an external SPI module that I bought on ebay based on the chip ENC28J60.
This is a simple item description:

  1. On-board ENC28J60 SSOP28 Mini Chip with Latest V2.0 PCB Layout version( Gain better EMC& Higher Speed)
  2. On-board 25MHz Crystal
  3. On-board HR911105A Ethernet DC converter(embedded status LED)
  4. 3.3V input Pin for power supply
  5. PCB Size: 44.5mm x 21mm

It offer an SPI standard communication,but after many days of trying I'm not been able to have a communication between arduino and this module.
The specific module is this: http://cgi.ebay.it/Mini-ENC28J60-V2-Ethernet-Module-AVR-PIC-ARM-MCU-/190534845895?pt=LH_DefaultDomain_0&hash=item2c5cc305c7#ht_2682wt_905 instead here http://www.megaupload.com/?d=L61RMUTW there's all material about this component (schematic,datasheet of ENC28J60,and some code example,i don't know how it work...)

I have read many material about SPI communication and the standard ethernet module of arduino,but I've not understood a lot...
Can someone help me to do a simple web server with this component?
I don't know if i can use the standard ethernet library or i should incapsulate readings and writes on web server with SPI shiftout function like this:

void spiWrite(byte data){
shiftOut(MOSI, SCK, MSBFIRST, data); // send to spi output
}

byte spiRead(){
byte value=0;
for(int i = 0; i<8; i++){
digitalWrite(SCK,LOW);
value = value << 1; // shift up for next byte read
value |= ( digitalRead(MISO) & 0x1); // add the next bit to the value
digitalWrite(SCK,HIGH);
}
digitalWrite(SCK,LOW); // put clock low at the end
return value;
}

Thank you in advance.

I don't know if i can use the standard ethernet library

Did you try it? It didn't work, did it?

Did you try googling Arduino + ENC28J60? There is a guy working on a library that will work with that chip, such that it looks a lot like the standard ethernet library.

You have said nothing about how YOU connected that device to your Arduino or if any of the LEDs on it light up or what issues you are having. Hard to help without a clue what you need help with.

Thank you to answer me Pauls;

You've right,i've omitted many details about my connection attempts (thanks to my inexperience).

I'm been able to give the power supply to the module (there's a led correctly lighted on the ethernet module when i link the GND arduino to the pin 8 of the module and the 3.3v output pin of arduino to module pin 1).
I've not linked to nothing the pin 2 of the ethernet module (the RST pin,coz I don't use it now),and the pin 7 too (ETH0-INT) coz I don't know what is it.
Instead I've linked the pin 3 (of the module,SPI-NSS)to the arduino pin 10,pin 4 (SPI-SCK) to arduino pin 13,pin 5(MOSI)to arduino pin 11,pin 6 (MISO) to arduino pin 12 as in the SPI library reference.
While I'm writing,it come in my mind a question:"Should i link the MISO module's pin to MOSI arduino's pin and vice-versa?" Now I've not done this,but I've directly linked MISO module to MISO arduino.
Obviously I tried to search on google,but what i found is material for standard arduino ethernet shield,that i don't know how it work,and how it's linked to arduino.

About the ethernet connection,I linked with ethernet cable my pc with ethernet module ,and I also tried directly my home router and ethernet module,but without communication results.
My principal problem is to have a simple communication between arduino and the module after some ethernet stimulus,like a ping or a tcp-ip packet from my pc to ethernet module address;It don't answer to the ping. The IP address i use is in the range of my local net,192.168.0.10 i.e. , and I'm sure is not used.As mac address,I've always used mac addresses found on the various examples on internet,coz I do not know the specific MAC address of my enc28j60 (is there a way to find my unic idenfier?).

I hope to have added more details to be well understood,in case please noted me if I can add more details that I escaped.

To be more clear I report a simple schematic connection of my actual situation:

PC or HOME ROUTER <----------------------------------------------->Ethernet module<---------------------------------->Arduino 2009
Ethernet cable
1 (3V) 3.3V
2 (RST) NO CONNECTION
3 (SPI-NSS) 10
4 (SPI-SCK) 13
5 (SPI-MOSI) 11
6 (SPI-MISO) 12
7 (ETH0-INT) NO CONNECTION
8 (GND) GND

LoScuby:
Hello Everybody,

This is my first post after some days of readings on this usefull forum;
I need help to interface my arduino 2009 and an external SPI module that I bought on ebay based on the chip ENC28J60.
This is a simple item description:

  1. On-board ENC28J60 SSOP28 Mini Chip with Latest V2.0 PCB Layout version( Gain better EMC& Higher Speed)
  2. On-board 25MHz Crystal
  3. On-board HR911105A Ethernet DC converter(embedded status LED)
  4. 3.3V input Pin for power supply
  5. PCB Size: 44.5mm x 21mm

It offer an SPI standard communication,but after many days of trying I'm not been able to have a communication between arduino and this module.
The specific module is this: http://cgi.ebay.it/Mini-ENC28J60-V2-Ethernet-Module-AVR-PIC-ARM-MCU-/190534845895?pt=LH_DefaultDomain_0&hash=item2c5cc305c7#ht_2682wt_905 instead here http://www.megaupload.com/?d=L61RMUTW there's all material about this component (schematic,datasheet of ENC28J60,and some code example,i don't know how it work...)

I have read many material about SPI communication and the standard ethernet module of arduino,but I've not understood a lot...
Can someone help me to do a simple web server with this component?
I don't know if i can use the standard ethernet library or i should incapsulate readings and writes on web server with SPI shiftout function like this:

void spiWrite(byte data){
shiftOut(MOSI, SCK, MSBFIRST, data); // send to spi output
}

byte spiRead(){
byte value=0;
for(int i = 0; i<8; i++){
digitalWrite(SCK,LOW);
value = value << 1; // shift up for next byte read
value |= ( digitalRead(MISO) & 0x1); // add the next bit to the value
digitalWrite(SCK,HIGH);
}
digitalWrite(SCK,LOW); // put clock low at the end
return value;
}

Thank you in advance.

There are libraries, such etherShield, that does the SPI communication to you, so you need just to develop your HTTP application, for example. These libraries are not the easiest to use (like the standard Arduino Ethernet library -- that is not compatible with ENC28J60). I'm developing a library that does the job: with the simple code you write using the standard Arduino Ethernet library, my library will 'talk' with ENC28J60, so you can use it in the easiest way.
It has some limitations now, but you can create a Web server. More information at: GitHub - turicas/Ethernet_ENC28J60: [NOT MAINTAINED, NOT COMPLETED] Implementation of an Arduino-compatible socket layer library that uses Microchip ENC28J60 Ethernet controller.

About the pin connections, please see this message: http://arduino.cc/forum/index.php/topic,68569.msg505946.html#msg505946

Thanks a lot Alvaro...

I will try immediately your library.

Thank you for your work(I hope to be able to use it...:D).

I tried your library Alvaro but it continue to do not work...
To be more clear on what i do during my attempts,I made a video,so you can see my real situation.

The connections i do are the same I wrote here:

PC or HOME ROUTER <----------------------------------------------->Ethernet module<---------------------------------->Arduino 2009
Ethernet cable
1 (3V) 3.3V
2 (RST) NO CONNECTION
3 (SPI-NSS) 10
4 (SPI-SCK) 13
5 (SPI-MOSI) 11
6 (SPI-MISO) 12
7 (ETH0-INT) NO CONNECTION
8 (GND) GND

And the schematic description of the ethernet module is here:

http://www.megaupload.com/?d=C1HJH3MG

I don't know where I wrong...

Thanks

The ethernet port on your computer is an input port. The Ethernet shield needs to be connected to an output port, on a router, not an input port on a PC.

I tried with my home router too...the result is exacltly the same...
I believe that on an ethernet communication there are not only input ports...ethernet is a protocol communication standard,so the "dialog" is a two way dialog (as the dialog word nature suggest).
The DHCP of the router (when it's connected directly to the router) do not assign the ip to arduino,and when i try to ping arduino from my pc,ping packets are discarded by the router coz the router hasn't a correspondance in its router table routing....It's the simpliest explanation that comes to mind...
In this arduino's ethernet library the DHCP politics are not been implemented i've read...so how it can work in the other internet example?

LoScuby:
I tried your library Alvaro but it continue to do not work...
To be more clear on what i do during my attempts,I made a video,so you can see my real situation.
- YouTube

The connections i do are the same I wrote here:

PC or HOME ROUTER <----------------------------------------------->Ethernet module<---------------------------------->Arduino 2009
Ethernet cable
1 (3V) 3.3V
2 (RST) NO CONNECTION
3 (SPI-NSS) 10
4 (SPI-SCK) 13
5 (SPI-MOSI) 11
6 (SPI-MISO) 12
7 (ETH0-INT) NO CONNECTION
8 (GND) GND

And the schematic description of the ethernet module is here:

http://www.megaupload.com/?d=C1HJH3MG

I don't know where I wrong...

Thanks

Some considerations about your video:

  • The RESET pin on ENC28J60 don't need to be connected to the RESET pin on Arduino. You can put it in 5V if it is activated on LOW (and on GND if it is activated on HIGH -- but I think it is activated on LOW).

  • You don't need to delete the standard Ethernet library. You can just put the folder "Ethernet_ENC28J60" in your "sketchbook/libraries/" folder.

  • The DHCP protocol is not implemented in my library, so you need to set the Arduino's IP and your PC's IP by hand! Put them in the same network. The IP starting with "169" is put on your machine when the operating system can't get an IP from the network. You need to fix an IP address like 192.168.0.1 for your PC and 192.168.0.2 for Arduino.

  • After correcting the problems above, try to just ping the Arduino and then try the HTTP request.

PaulS:
The ethernet port on your computer is an input port. The Ethernet shield needs to be connected to an output port, on a router, not an input port on a PC.

You are wrong! Yes, we can have Ethernet peer-to-peer connections. :slight_smile: In some years ago we needed a special cable (crossover cable) that have some pins inverted, but nowadays, all modern network cards have the automatic switch between RX and TX when it detects it.
I made my tests here with either my Arduino connected directly to my PC and to my Wi-Fi access point.

I've assigned a static ip address to my pc through the properties of the lan connection (192.168.0.1) and via code also to arduino 192.168.0.2 but no communication yet....
the only thing I discovered is that my ethernet module is resetted on ground link...
I attempted to reverse the situation,so arduino is not more the server using the webclient example,and sniffing the packets of my pc,but no packets are ever arrived from the arduino's ip (in no one port by its ip address).
I'm beginning to think that my ethernet module do not work properly...

LoScuby:
I've assigned a static ip address to my pc through the properties of the lan connection (192.168.0.1) and via code also to arduino 192.168.0.2 but no communication yet....
the only thing I discovered is that my ethernet module is resetted on ground link...
I attempted to reverse the situation,so arduino is not more the server using the webclient example,and sniffing the packets of my pc,but no packets are ever arrived from the arduino's ip (in no one port by its ip address).
I'm beginning to think that my ethernet module do not work properly...

My library does not work as TCP client yet, so Web client example will not work. It only works for HTTP server example (use WebServerSimpleLED example). Can you ping Arduino?

Also this attempt to contact arduino with a ping is not gone well...nothing...no answer...

I've setted up a fixed ip to my pc in the connection properties,but i continue to do not have a signal...
Do not work WebServerSimple,and WebServerSimpleLED code.....

Ethernet module and my pc's ethernet card apparently trying to send signal in the cable,but they are not able to contact each other.

LoScuby:
Also this attempt to contact arduino with a ping is not gone well...nothing...no answer...

I've setted up a fixed ip to my pc in the connection properties,but i continue to do not have a signal...
Do not work WebServerSimple,and WebServerSimpleLED code.....

Ethernet module and my pc's ethernet card apparently trying to send signal in the cable,but they are not able to contact each other.

What Arduino/ATMega are you using?
I want to know if you are compiling the example with my library, instead of the standard Ethernet library. What is the size of compiled code for the WebServerSimpleLED example?

I'm using an arduino 2009 and the size is:

"Binary sketch size: 10070 bytes (of a 30720 byte maximum)".

Alvaro ,Thank you very much for your support...

LoScuby:
I'm using an arduino 2009 and the size is:

"Binary sketch size: 10070 bytes (of a 30720 byte maximum)".

Alvaro ,Thank you very much for your support...

Here the size of the example WebServerSimpleLED compiled to Arduino Duemilanove is 10,018 bytes. So, I think you are not compiling the same thing. Maybe you are not compiling the standard Arduino Ethernet library because it generally has smaller size than my library. But, if your compiled code is greater than mine, probably you are compiling something different from me.

Is the debugging feature enabled? Check if the line "#define ETHERSHIELD_DEBUG" utils/socket.h is commented.

alvarojusten:

LoScuby:
I'm using an arduino 2009 and the size is:

"Binary sketch size: 10070 bytes (of a 30720 byte maximum)".

Alvaro ,Thank you very much for your support...

Here the size of the example WebServerSimpleLED compiled to Arduino Duemilanove is 10,018 bytes. So, I think you are not compiling the same thing. Maybe you are not compiling the standard Arduino Ethernet library because it generally has smaller size than my library. But, if your compiled code is greater than mine, probably you are compiling something different from me.

Is the debugging feature enabled? Check if the line "#define ETHERSHIELD_DEBUG" utils/socket.h is commented.

No,the ETHERSHIELD_DEBUG line is commented in utils/socket.h ...If i "de-comment" this line,the new binary sketch is 13162 bytes.
I tried to eliminate all libraries in the library directory of arduino's IDE;I've re-downloaded from your link GitHub - turicas/Ethernet_ENC28J60: [NOT MAINTAINED, NOT COMPLETED] Implementation of an Arduino-compatible socket layer library that uses Microchip ENC28J60 Ethernet controller. from the button download easly,I've extracted it with winrar and i've re-named the directory extracted,cause Arduino's IDE otherwise say me that the library's name should contains only basic numbers and ASCII characters,so new name is turicas.When i compile the size of the binary rest the same I posted you some post ago(10070 bytes).
The version of Arduino's IDE I use is the 022,and the java version on my system is 1.6.0.25 (64 bit version...)

The sketch i compile is which i found on the library's examples named WebServerSimpleLED (as you suggested to compile)
Its content is this:

#include <Ethernet.h>
#define LED 8

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 123 };
char link[30], LEDStatus[4];

Server server(80);

void setup() {
pinMode(LED, OUTPUT);
Ethernet.begin(mac, ip);
server.begin();
}

void loop() {
Client client = server.available();
if (client) {
char request[10];
int i = 0;
boolean current_line_is_blank = true;
request[9] = '\0';
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (i < 9) {
request = c;

  • i++;*

  • }*

  • if (c == '\n' && current_line_is_blank) {*

  • client.println("HTTP/1.1 200 OK");*

  • client.println("Content-Type: text/html");*

  • client.println();*

  • client.println("Arduino etherShield");*

  • client.println("

    Arduino etherShield Example

    ");*

  • client.println("

    ");*

  • client.print("

  • ");*

  • if (strncmp("GET /off", request, 8) == 0) {*

  • digitalWrite(LED, LOW);*

  • sprintf(LEDStatus, "OFF");*

  • sprintf(link, "<a href="/on">Turn on");*

  • }*

  • else {*

  • sprintf(LEDStatus, "ON");*

  • digitalWrite(LED, HIGH);*

  • sprintf(link, "<a href="/off">Turn off");*

  • }*

  • client.print("

  • <td colspan="2" align="center">");*

  • client.println(link);*

  • client.println("

  • Analog inputs: ");*

  • for (int x = 0; x < 6; x++) {*

  • client.print(x);*

  • client.print(" = ");*
    _ client.print(5000 * (analogRead(x) / 1024.0));_

  • client.print(" mV*
    ");

  • }*

  • client.println("

  • uptime: ");*

  • client.print(millis() / 1000.0);*

  • client.println(" seconds

  • LED status: ");*

  • client.print(LEDStatus);*

  • client.println("

  • ");*

  • break;*

  • }*

  • if (c == '\n') {*

  • current_line_is_blank = true;*

  • } else if (c != '\r') {*

  • current_line_is_blank = false;*

  • }*

  • }*

  • }*

  • delay(1);*

  • client.stop();*

  • }*
    }
    At this point,if you can send me your binary file of WebServerSimpleLED ,if you can,so i can try it and eliminate all duobts about the compiled file version that i use...
    Thanks