ENC28J60 on Netduino2Plus

Limited support for STM32F4 Discovery, Nucleo and custom F4 boards
Quintessence
Posts: 4
Joined: Tue May 10, 2016 10:17 pm

Re: ENC28J60 on Netduino2Plus

Post by Quintessence » Wed May 11, 2016 1:10 pm

Thank you a lot for your help and the quick answer ! :)


The Serial print works well on the arduino board, it is the standard Example sketch from the UIPEthernet Library :

Code: Select all

 
#include <UIPEthernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,6);

// telnet defaults to port 23
EthernetServer server(23);

EthernetClient clients[4];

void setup() {
  // initialize the ethernet device
  Ethernet.begin(mac, ip);
  // start listening for clients
  server.begin();
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Chat server address:");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // wait for a new client:
  EthernetClient client = server.available();

  if (client) {

    boolean newClient = true;
    for (byte i=0;i<4;i++) {
      //check whether this client refers to the same socket as one of the existing instances:
      if (clients[i]==client) {
        newClient = false;
        break;
      }
    }

    if (newClient) {
      //check which of the existing clients can be overridden:
      for (byte i=0;i<4;i++) {
        if (!clients[i] && clients[i]!=client) {
          clients[i] = client;
          // clead out the input buffer:
          client.flush();
          // clead out the input buffer:
          client.flush();
          Serial.println("We have a new client");
          client.println("Hello, client!");
          client.print("my IP: ");
          client.println(Ethernet.localIP());
          break;
        }
      }
    }

    if (client.available() > 0) {
      // read the bytes incoming from the client:
      char thisChar = client.read();
      // echo the bytes back to all other connected clients:
      for (byte i=0;i<4;i++) {
        if (clients[i] && clients[i]!=client) {
          clients[i].write(thisChar);
        }
      }
      // echo the bytes to the server as well:
      Serial.write(thisChar);
    }
  }
  for (byte i=0;i<4;i++) {
    if (!(clients[i].connected())) {
      // client.stop() invalidates the internal socket-descriptor, so next use of == will allways return false;
      clients[i].stop();
    }
  }
}
I also tried the other examples and tried to get ping answers, but I got no answer. I tried it for 2 days, so I thought it would be better to ask, if something is wrong here.

My setup: BluePill, Arduino 1.6.7 programming the board now works fine Serial connection as well.The UIP Library is copied from the Git Repository, from the STM32F4 Folder into my Library folder without any changes. Maybe the Library for the F4 is not completely compatible to the F1? I'm just guessing.

Three minutes ago I tried the ENC28J60 with my Arduino Uno and it works great.

User avatar
martinayotte
Posts: 1183
Joined: Mon Apr 27, 2015 1:45 pm

Re: ENC28J60 on Netduino2Plus

Post by martinayotte » Wed May 11, 2016 2:46 pm

For the Serial.println(Ethernet.localIP());, I'm surprised that it is working fine on Arduino boards, because Ethernet.localIP() is returning an IPAddress, not a string. In fact, in STM32, I've added a method to be print friendly : so, Serial.println(Ethernet.localIP().toString()); should print it correctly.

If I remember, yes, I've simply copied the STM32F4/libraries/arduino_uip into STM32F1/libraries/arduino_uip, (or probably created a symbolic link).

I would need to setup my MapleMini and try the above sketch again to see how it is reacting on my side, but unfortunately, I'm currently lacking of the "time ingredient", so it can take awhile...

Quintessence
Posts: 4
Joined: Tue May 10, 2016 10:17 pm

Re: ENC28J60 on Netduino2Plus

Post by Quintessence » Thu May 12, 2016 7:12 pm

martinayotte wrote:For the Serial.println(Ethernet.localIP());, I'm surprised that it is working fine on Arduino boards, because Ethernet.localIP() is returning an IPAddress, not a string. In fact, in STM32, I've added a method to be print friendly : so, Serial.println(Ethernet.localIP().toString()); should print it correctly.
I rechecked it with the UNO sketch and it's the same, maybe there is a macro in the background, which converts the IP Adress into a string for printing it out. Your .toString()) method does not exist in my version of the library, I'm sorry :( , I got:

Code: Select all

AdvancedChatServer:49: error: 'class IPAddress' has no member named 'toString'
   Serial.println(Ethernet.localIP().toString()); 
                                     ^
exit status 1
'class IPAddress' has no member named 'toString'
I checked my Bluepill with the Ethercard_STM library and it was accessable via ping and the example sketches worked fine, so the Bluepill and the shield isn't damaged I think.

Just to be sure: The correct wiring for the UIP Ethernet library is the same like in the ethernet library, isn't it?:
SS PA4
SCK PA5
MISO PA6
MOSI PA7

I also tried out PA8 as SS Pin like in the Ethercard library and wiring up on SPI Port 2 also as a variation with SS on PA8:

SS <--> PB12 <--> BOARD_SPI2_NSS_PIN
SCK <--> PB13 <--> BOARD_SPI2_SCK_PIN
MISO <--> PB14 <--> BOARD_SPI2_MISO_PIN
MOSI <--> PB15 <--> BOARD_SPI2_MOSI_PIN

Sadly none of the combinations worked.
martinayotte wrote: I would need to setup my MapleMini and try the above sketch again to see how it is reacting on my side, but unfortunately, I'm currently lacking of the "time ingredient", so it can take awhile...
That's totally fine, it's really great that you responded so fast, so please don't feel stressed ! ;)

User avatar
martinayotte
Posts: 1183
Joined: Mon Apr 27, 2015 1:45 pm

Re: ENC28J60 on Netduino2Plus

Post by martinayotte » Thu May 12, 2016 10:53 pm

Hi Quintessence,

For the IPAddress.toString(), it has been committed more than 2 months ago, so maybe your installation isn't up-to-date.

https://github.com/rogerclarkmelbourne/ ... cba714aa01

Of course, I wish to give it a try again, but I can't commit when ("time is the missing ingredient") ... ;)

Quintessence
Posts: 4
Joined: Tue May 10, 2016 10:17 pm

Re: ENC28J60 on Netduino2Plus

Post by Quintessence » Sun May 15, 2016 10:59 am

Finally it worked !! :)
martinayotte wrote: For the IPAddress.toString(), it has been committed more than 2 months ago, so maybe your installation isn't up-to-date.
That problem was: I used the board manager to install the boards, but Version 1.0.8 seems not to be the latest version, so I removed it and installed the Git Files. First it din't work, because you have to additionally include the SPI.h in the sketch, which you do not need with the Uno, after that everything worked fine :)

THANK YOU A LOT Martinayotte and the others. It's great to use the STM32 with arduino and I hope this community will grow in the future !

Would it help if I start a new topic in "Ported Librarys" with my experiences with the BluePill + 28j60 ?

Greets from germany ! :)

User avatar
martinayotte
Posts: 1183
Joined: Mon Apr 27, 2015 1:45 pm

Re: ENC28J60 on Netduino2Plus

Post by martinayotte » Sun May 15, 2016 1:11 pm

Good !
So, you can now enjoy the internet from the BluePill ... ;)

cassyarduino
Posts: 15
Joined: Tue Nov 08, 2016 12:52 pm
Location: Hungary

Re: ENC28J60 on Netduino2Plus

Post by cassyarduino » Tue Nov 08, 2016 1:04 pm

Hi all!

I working with leaflab 'maple mini' (STM32F103CBT6) and ENC28j60.
I compiled project with my modified UIPEthernet library with arduino IDE 1.6.9.
Original UIPEthernet writed by Norbert Truchsess.
You can download from https://github.com/ntruchsess/arduino_uip
You can download my modified version UIPEthernet from:http://www.zalaszam.hu/~cassy/devel/avr/UIPEthernet.zip
The wiring for 'maple mini' and ENC28j60:http://www.zalaszam.hu/~cassy/devel/ard ... wiring.PNG

Best Regards!

stevestrong
Posts: 1338
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: ENC28J60 on Netduino2Plus

Post by stevestrong » Tue Nov 08, 2016 3:19 pm

@cassyarduino,
can you tell us what did you modify on the UIPEthernet lib?
Maybe is relevant for the original lib as well.

cassyarduino
Posts: 15
Joined: Tue Nov 08, 2016 12:52 pm
Location: Hungary

Re: ENC28J60 on Netduino2Plus

Post by cassyarduino » Wed Nov 09, 2016 8:31 am

Hi All!

I modified the code:

- Replaced import to include, because gcc say 'import is deprecated'.
- I merged martinayotte's modification (Correct s_dhcp ~40K more memory usage with STM32F MCU-s.)
- Add support for STM32F, and ESP8266 MCU-s.
- Moved htons,ntohs,htonl,ntohl definitions to uip.h.
- Correct infinite loops.

Compililation tested: ATMEGA328P,ArduinoDue,Maple Mini,ESP8266.

Best Regards!

User avatar
zoomx
Posts: 450
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: ENC28J60 on Netduino2Plus

Post by zoomx » Wed Nov 09, 2016 9:46 am

Well done!

I didn't know this library, I know only the ethercard library but reading here
http://www.tweaking4all.com/hardware/ar ... -ethernet/
where libraries are compared, it seem that UIPEthernet is better.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest