Problems with Arduino DUE and ENC28J60.

Hi people

:slight_smile:

First to say sorry about my English.

I need some help, I want to begin using Arduino, I was working with Microchip, but I need more speed and I/O Ports, so I just bougth an Arduino DUE. CortexM3 ARM based board.

The question is that I have a few Enc28j60 Modules and I wish to use it with my new Arduino due, So I was searching in the web And I can´t find any working example.

I just tried with a few examples but having problems.

Please help me, I don´t want to go back to Microchip.

A big hug from Colombia.

Luis.

Poke through GitHub - njh/EtherCard: EtherCard is an IPv4 driver for the ENC28J60 chip, compatible with Arduino IDE

The library includes examples.

Many thanks,

I already was tried these one,but when I try to compile examples I have problems with AVR files, then when I try to show to the compiler, where de files are,

It shows another kind of error.

=( =(

You need to tell us what the error is.

Basically only official sketches that runs over Arduino UNO can run directly (or with few effort) on Arduino DUE, this because the Arduino core (the libraries) was migrated for the ARM CPU used in the DUE. Every other Arduino sketch won't run without a porting.

Some non-official Arduino sketches that runs UNO may run also on DUE, it depends if they are based on custom libraries or if are based only on the Arduino core, in the latter case it should run. The EtherCard library has an its own SPI driver (doesn't use the Arduino ones) and this is creating your problems.

I've never been in detail with ARM, so I don't know if there are others to be considered. As minimum you need to review all pins assignment and all direct access to register and interrupts, it should be not so hard, because the library doesn't use a lot of those.

I can try to help if you want.

Regards,
Dario.

Thanks Dario.

You are so nice trying to explain the problem.

And exactly if I try to compile the code built in Arduino examples, it compiles well, but when I change to my Arduino DUE. it crash.

I have downloaded a lot of examples (there are many of them), but I can´t find any for the DUE.

If you want to help me, I really would appreciate it.

So, what is the next step?

Best regards.

Luis.

P.D: Spanish is my language, so my apologies.

English isn't mine :slight_smile:

First step is to have a look to the official SPI drivers and port your code using that drivers instead of the one included in Ethercard (or any other that you are using), then look if you have still compilation errors and move forward.

Regards,
Dario.

This will probably cause problems with SPI devices connected to a Due.

The Due needs an additional parameter to continue sending additional bytes over the SPI. Otherwise, it deactivates the SPI slave select after each call to SPI.transfer().

Hello.

Sorry I was working and I have not time to test your teory.

I think this weekend I will.

Thanks a lot.

Luis.

:astonished:

Ok I can´t wait,

I go to this page, Tecnotinker - Electrónica digital, robótica y automatización: Uso del módulo ethernet ENC28J60 con Arduino : Parte 1 , he says it works with Arduino UNO, I try to compile it with my Arduino DUE, and again error.

The next image shows that the picture are like´s an attachment.

Thanks a lot.

Luis.

just got ENC28J60 running with Arduino DUE with UIPEthernet-library.
Not release or merged in branch master yet, code resides in branch 'due'. (You can download complete branch as zip-file).
To install first unzip, then add the library by going to 'sketch'->'import library'->'add library', then navigate to the directory you have unzipped the library to and select directory 'UIPEthernet', then click 'open'. Afterwards you will find new examples (AdvancedChatServer, EchoServer, TcpClient, TcpServer, UdpClient and UdpServer) for UIPEthernet in 'file'->'examples'->'UIPEthernet'

I use Arduino 1.5.5, the ENC28J60 is connected to SPI on ICSP-header, CS is connected to pin 10.

Examples from UIPEthernet run without modifications, WebServer-example from Ethernet-lib runs by replacing include 'Ethernet.h' by 'UIPEthernet.h' (not removing the SPI.h, as this is required on DUE).

Have fun!

  • Norbert

Hi Norbert

First I wish to thank you for your library.

I'm trying to use it with Arduino DUE, but I have a problem:
I only can make it work if I connect the ENC28j60 CS to pin 52 , but I wish to use pin 10 for CS.

To make it work on pin 52 I also have to change line 30 in Enc28J60Network.h from #define ENC28J60_CONTROL_CS SS
to #define ENC28J60_CONTROL_CS 52. In this line I have tried change 52 to 10, but if I do that it stops working.

What I'm doing wrong, or for now it only works on a DUE with CS connected to pin 52?

I have connect ENC28j60 on Arduino Due SPI header.

Thanks

@ntruchsess could you help me getting your library work for the arduino send e-mail sketch? When I upload the sketch with your library it says connected and then prints an endless line of ÿÿÿ... I don't know what I am doing wrong.
I also use a ENC28J60.

cpu20:
When I upload the sketch with your library it says connected and then prints an endless line of ÿÿÿ... I don't know what I am doing wrong.

I don't know either. And without seeing the sketch you upload this ain't change.

////
//
// General code from http://www.pushingbox.com for Arduino + Ethernet Shield (official) v1.2
//
////

#include <SPI.h>
#include <UIPEthernet.h>

  /////////////////
 // MODIFY HERE //
/////////////////
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };   // Be sure this address is unique in your network
IPAddress ip(192,168,1, 20);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255,255, 0);

//Your secret DevID from PushingBox.com. You can use multiple DevID  on multiple Pin if you want
char DEVID1[] = "PushBoxCode ";        //Scenario : "The mailbox is open"

//Numeric Pin where you connect your switch
uint8_t pinDevid1 = 3; // Example : the mailbox switch is connect to the Pin 3

// Debug mode
boolean DEBUG = true;
  //////////////
 //   End    //
//////////////


char serverName[] = "api.pushingbox.com";
boolean pinDevid1State = false;                // Save the last state of the Pin for DEVID1
boolean lastConnected = false;                 // State of the connection last time through the main loop


// Initialize the Ethernet client library
// with the IP address and port of the server 
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  Serial.begin(9600);
  pinMode(pinDevid1, INPUT);
  
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
  else{
    Serial.println("Ethernet ready");
    // print the Ethernet board/shield's IP address:
    Serial.print("My IP address: ");
    Serial.println(Ethernet.localIP());
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
}

void loop()
{
      ////
      // Listening for the pinDevid1 state
      ////
      if (digitalRead(pinDevid1) == HIGH && pinDevid1State == false) // switch on pinDevid1 is ON 
      {
        if(DEBUG){Serial.println("pinDevid1 is HIGH");}
        pinDevid1State = true;
        //Sending request to PushingBox when the pin is HIGHT
        sendToPushingBox(DEVID1);
      }
       if (digitalRead(pinDevid1) == LOW && pinDevid1State == true) // switch on pinDevid1 is OFF
      {
        if(DEBUG){Serial.println("pinDevid1 is LOW");}
        pinDevid1State = false;
        //Sending request to PushingBox when the pin is LOW
        //sendToPushingBox(DEVID1);    //Here you can run an other scenario by creating a DEVID2 variable
      }
      
      
      //DEBUG part
      // this write the respons from PushingBox Server.
      // You should see a "200 OK"
      if (client.available()) {
        char c = client.read();
        if(DEBUG){Serial.print(c);}
      }
      
      // if there's no net connection, but there was one last time
      // through the loop, then stop the client:
      if (!client.connected() && lastConnected) {
        if(DEBUG){Serial.println();}
        if(DEBUG){Serial.println("disconnecting.");}
        client.stop();
      }
      lastConnected = client.connected();
}


//Function for sending the request to PushingBox
void sendToPushingBox(char devid[]){
  client.stop();
  if(DEBUG){Serial.println("connecting...");}

  if (client.connect(serverName, 80)) {
    if(DEBUG){Serial.println("connected");}

    if(DEBUG){Serial.println("sendind request");}
    client.print("GET /pushingbox?devid=");
    client.print(devid);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(serverName);
    client.println("User-Agent: Arduino");
    client.println();
  } 
  else {
    if(DEBUG){Serial.println("connection failed");}
  }
}

This is my current output:

I could get to connecting by changing something in the UIPClient.cpp file. I changed in the available function the return -1 to return 0. This got me to connecting...

Edit: I found that in the file Dns.cpp the progam get stuck. Trough the function Client.connect the program get to ProcessResponse in the Dns.cpp file. Here it gets stuck in the while loop on line 325. I have no idea why but that's why it never connects.

cpu20:
I could get to connecting by changing something in the UIPClient.cpp file. I changed in the available function the return -1 to return 0. This got me to connecting...

Seems you are not on the latest code:
UIPClient::available will not return -1

All 1.5x-Versions since 1.52 support Due (guess I should delete the outdated branch 'due' that I used to implement due-support though...)

I used the "old" due library from your releases. But now that I use the latest release I get a whole bunch of errors...
The most frequent one is this:
C:\Program Files (x86)\Arduino\libraries\UIPEthernet\src\UIPClient.cpp:246:30: error: 'class UIPEthernetClass' has no member named 'network'

Did I do something wrong installing the library?

cpu20:
Did I do something wrong installing the library?

Good question, I just tried the 1.57 download I linked before in fresh installed Arduino-1.5.7 IDE (on Linux though...) by coying the UIPEthernet-folder to the library-folder of the Arduino install. All examples compiled fine...

on my install UIPClient.cpp is located here:
/home/norbert/bin/arduino-1.5.7/libraries/UIPEthernet/src/UIPClient.cpp

from my understanding your Windows-install directories seem to be equivalent. Is it possible that you just copied the new files into the old location so you now have a mixed install?

  • Norbert

It would surprise me that linux and windows would be such a big difference. I completely deleted the UIPEthernet folder and then installed the new one. I can't compile any example. I then rolled back to v1.5.5IDE to see if that helps but the same errors appear... And here everything was fresh. A whole new librarie folder.
I can compile everything you wrote before v1.56. But in v1.56 I get less errors then in 1.57. Those errors are conversion errors.
If you compile your libraries on linux in arduino IDE do you select the arduino due programming port as device?
I will look further into these errors. Why it says that there is no network class...

Hi I'm Michael from Germany,

Sorry my English is not so good.

I am new to Arduino and precisely the DUE and wants to let the DUE runinter alia as a Web server with the ENC28J60-board.

I use the files from ntruchsess. (Many thanks to ntruchsess)

But I have a problem. Think it has something to do with the SPI.
In itself, the connection is established. But the construction and connection of the HTML page is not correct / good.

My Settings in the Enc28J60Network.h:

#define ENC28J60_CONTROL_CS BOARD_SPI_SS0

#define SPI_MOSI 109
#define SPI_MISO 108
#define SPI_SCK 110
#define SPI_SS BOARD_SPI_SS0

My Settings in the Enc28J60Network.cpp:

#define ENC28J60DEBUG

tried various settings....
SPI.setClockDivider (4); // (21)
SPI.setClockDivider (10); //(8)
SPI.setClockDivider (21); // (4)

I post sometimes the code and some pictures and hope you can help me.

If I use this code nothing happens in the browser (image)

/*
  Web Server
*/

#include <SPI.h>
#include <UIPEthernet.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

IPAddress ip(192, 168, 178, 88);

EthernetServer server(80);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server run on IP ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  EthernetClient client = server.available();
  if (client) {
   Serial.println("new client");
    boolean currentLineIsBlank = true;
   while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        delay(1);
        if(c == '\n' && currentLineIsBlank){
           Serial.println("Print page...");
           delay(1);
           client.println("HTTP/1.1 200 OK");
           delay(1);
           client.println("Content-Type : text/html");
           delay(1);
           client.println("Connection : close");
           delay(1);
           client.println("Refresh: 5");  
           delay(1);
           client.println();
           client.println();
           delay(1);
           client.println("<!DOCTYPE HTML>");
           delay(1);
           client.println("<HTML>");
           client.println("<HEAD>");
           delay(1);
           client.println("<TITLE>TEST PAGE</TITLE>");
           client.println("</HEAD>");
           client.println("<BODY>");
           client.println("<H1>TEST PAGE 2</H1>");
           client.println("<hr />");
           client.println("
");  
           delay(1);
           client.println("<H2>Arduino DUE with ENC28J60</H2>");
           client.println("
");
           client.println("
");   
           client.println("
");
           client.println("
");
           client.println("</BODY>");
           client.println("</HTML>");
           break;
           }
           if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
          Serial.println("currentLineIsBlank = true;");
          }
          else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
          Serial.println("currentLineIsBlank = false;");
         }
      }
   }
   // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
 } 
}


If I change the code this happens (image)

/*
  Web Server
*/

#include <SPI.h>
#include <UIPEthernet.h>

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

IPAddress ip(192, 168, 178, 88);

EthernetServer server(80);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server run on IP ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  EthernetClient client = server.available();
  if (client) {
   Serial.println("new client");
    boolean currentLineIsBlank = true;
   while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        delay(1);
///////////////////////////////////////////////////////////////////////////
///// if(c != '\n' && currentLineIsBlank){      /// Change  == to !=///
///////////////////////////////////////////////////////////////////////////
           Serial.println("Print page...");
           delay(1);
           client.println("HTTP/1.1 200 OK");
           delay(1);
           client.println("Content-Type : text/html");
           delay(1);
           client.println("Connection : close");
           delay(1);
           client.println("Refresh: 5");  
           delay(1);
           client.println();
           client.println();
           delay(1);
           client.println("<!DOCTYPE HTML>");
           delay(1);
           client.println("<HTML>");
           client.println("<HEAD>");
           delay(1);
           client.println("<TITLE>TEST PAGE</TITLE>");
           client.println("</HEAD>");
           client.println("<BODY>");
           client.println("<H1>TEST PAGE 2</H1>");
           client.println("<hr />");
           client.println("
");  
           delay(1);
           client.println("<H2>Arduino DUE with ENC28J60</H2>");
           client.println("
");
           client.println("
");   
           client.println("
");
           client.println("
");
           client.println("</BODY>");
           client.println("</HTML>");
           break;
           }
           if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
          Serial.println("currentLineIsBlank = true;");
          }
          else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
          Serial.println("currentLineIsBlank = false;");
         }
      }
   }
   // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
 } 
}


And if I change #define ENC28J60DEBUG to //#define ENC28J60DEBUG in the Enc28J60Network.cpp file.
happens this.

Thank you!
Greetings Michael