Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Problems with ENC28J60 losing connection/freezing (using UIPEthernet or etherShield)? READ THIS!

Problems with ENC28J60 losing connection/freezing (using UIPEthernet or etherShield)? READ THIS!

Scheduled Pinned Locked Moved Troubleshooting
enc28j60
50 Posts 16 Posters 45.3k Views 9 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    ntruchsess
    Plugin Developer
    wrote on last edited by
    #34

    For TCP you are right - the boolean return-value is not required as the library does free memory not before a packet is acknowledged or the connection is closed. I guess here I can remove some code from the lib. UDP does not retransmit and would loose packets just because of collisions. UDP should loose packets only when they time out or get dropped due to physical failure.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eli81
      wrote on last edited by Eli81
      #35

      Hi Everyone,

      I wanted to report my experience here as I thought you all would probably be able to understand it far better than I can, and maybe even find it interesting. I'm a newbie, so bare with me...

      For the longest time, I was using the UIPEthernet library 'improperly'. I wanted to open a connection and keep it opened(indefinitely if necesssary), and "stream" my data to my program - a long string of text parameters, about 200 bytes. The easiest way to do this seemed to be just simply not disconnect. Using the basic examples as a starting point however, this results in the need to "ping" the Arduino every time you want data, resulting in a perpetual game of "ping/pong". The connection never actually closes, but using client = server.available(); to call your actions causes this I guess, since it only returns 1 if there is data waiting to be read. This is what all of the examples seemed to use, so I thought it was the right way. Adding fuel to the flames, I found a blog that seemed to call this a bug, and showed how to fix it with the stock Ethernet library, so I thought I was on the right track. I wanted to use UIPEthernet though, and the ping/pong scheme seemed workable, if kludgey, so I implemented it. I had it working for a long time - a couple of months - without any trouble overall. I mean, I could open a telnet session with PuTTY and have it sit there open for days and randomly "ping" the arduino and get a packet.

      However, I just knew it didn't seem right, and like I said it was kludgey, made all of the other things I was having the Arduino do all the more difficult. I wanted to fix it, to the point of making a fool of myself asking about it on the Arduino forums.

      So anyway, after studying some other examples for a while, and reading some other things, I figured out the "proper" way to do things - store your (up to 4 connections) in an array; that way you can check them for (dis)connections, send data to individual ones, etc. Elementary I assume, but like I said .. you gotta start somewhere. ;) Fantastic! No more pinging!

      Except now I've lost the stability I had. Couldn't keep a connection for more than 12 hours it seemed, let alone the days and weeks I had before. Frustrated, I basically dropped the project for a couple of weeks. The other day I decided to pick it up in earnest again. I couldn't find anything wrong with my code after going over and over it, so I hit google again..

      This thread came up, and seemed pertinent. I installed the fix version of the library, and what do you know - stability. :) Been almost 48 hours now. Nothing else has changed, so I'm going to call it fixed. I don't really know what to make of all that, but I find it interesting that I had such great stability using the first method overall, even though it was "wrong".

      I want to thank everyone for their efforts, especially Norbert for the superb support of his library. It truly makes it a pleasure to use. I can only hope I can contribute to the general community on such a high level one day.

      Edit: 72 hours+ and still going strong.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Max
        wrote on last edited by
        #36

        Using official Arduino Mega ADK via proper 3.3V level shifter. Powering ENC with 3.3V from the same Arduino.

        ENC stopped responding to pings after just one night. The main program continues to work.

        The main program polls 1-wire temperature sensor, displays the temperature to an SPI display and controls another device using standard digital outputs.

        I strongly suspect that the problem is in Errata 14.

        If I have some time (which is not likely to happen any time soon) I'll look into it and will try to fix it for EtherCard library as it is smaller for I will need all that stuff to fit into Pro Mini based on ATmega 328.

        1 Reply Last reply
        0
        • axillentA Offline
          axillentA Offline
          axillent
          Mod
          wrote on last edited by
          #37

          Hi!

          Are any fix was applied to 1.4.1 EthernetGateway?

          Just build it based on atmega128A (need more flash to implement DHCP later).
          It is running without any issue for a day.

          sense and drive

          1 Reply Last reply
          0
          • axillentA Offline
            axillentA Offline
            axillent
            Mod
            wrote on last edited by
            #38

            ha!

            everyone have to care about the source. Have t measure the source current and have added a multimeter.This probably add very small voltage drop, but it was more than enough for ping to start loosing packets! It is very sensitive to the power source. After adding just 0.2V pings stop been lost.

            sense and drive

            m26872M 1 Reply Last reply
            0
            • axillentA axillent

              ha!

              everyone have to care about the source. Have t measure the source current and have added a multimeter.This probably add very small voltage drop, but it was more than enough for ping to start loosing packets! It is very sensitive to the power source. After adding just 0.2V pings stop been lost.

              m26872M Offline
              m26872M Offline
              m26872
              Hardware Contributor
              wrote on last edited by
              #39

              @axillent said:

              After adding just 0.2V pings stop been lost.

              You're saying that you got it back to life without doing a reset or interrupt the supply first?

              axillentA 1 Reply Last reply
              0
              • m26872M m26872

                @axillent said:

                After adding just 0.2V pings stop been lost.

                You're saying that you got it back to life without doing a reset or interrupt the supply first?

                axillentA Offline
                axillentA Offline
                axillent
                Mod
                wrote on last edited by
                #40

                @m26872 said:

                You're saying that you got it back to life without doing a reset or interrupt the supply first?

                I'm not looking for the extreme recovery abilities)
                My steps are:

                • multimeter added to measure current between +3.3V source and VCC pin on ENC shield

                • power on

                • result - many ping were lost

                • power off

                • 3.3V source was turned 0.2V up

                • power on

                • result - none of ping were lost

                sense and drive

                1 Reply Last reply
                0
                • stevebusS Offline
                  stevebusS Offline
                  stevebus
                  wrote on last edited by
                  #41

                  So glad to have found this thread! Sounds like the exact problem I've been having. Ethernet gateway, with enc28j60 shield would randomly stop responding to Vera, to telnet (on 5003) and to pings. Sometimes in hours, occasionally making it a few days. Looking at my sensors, the radio stack is still working fine, the Ethernet side of the GW is just a dead stick.

                  I replaced my UIPEthernet files with the ones from GitHub above, disabled DEBUG and UDP to get it to fit, re-compiled, and re-deployed. Will report back how it goes!

                  BTW - the statement above says: "•DON'T activate the DEBUG-flag in MyConfig.h because this definitely will 'break' the gateway." I had to turn off DEBUG to fit the code on my UNO anyway, but I'm curious to why having DEBUG on breaks gateways?? (I had DEBUG on in my previous version with the old UIPEthernet files.. Did it contribute to my issue?).

                  Vera Edge/UI7; mysensors; Arduino's and RPIs; data posted to Azure for an IoT 'dashboard' of my house

                  Opinions expressed here are my own and do not necessarily reflect Microsoft's feelings on a given topic :-)

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    nottledim
                    wrote on last edited by
                    #42

                    My Mega app was surviving maybe as much as 5 minutes using the UIPEthernet library for Arduino >= 1.5. I made the changes as you suggest noting in particular that the reset has to come first. It's now been running flawlessly for 48hrs. I have have great hopes for this continuing.

                    I don't understand why this is still not in the main distribution after so long.

                    Anyway many thanks for posting this solution. It's a lifesaver.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Marcell Kovacs
                      wrote on last edited by Marcell Kovacs
                      #43

                      Thank you for this post! Saved the day!
                      Just for information, im using EtherShield, with this lib: https://github.com/jonoxer/etherShield/blob/master/enc28j60.c
                      (it has ugly limitations, but has the smallest memory requirement in my case)

                      The solution fits almost exactly, with some small modifications (around line 290):

                      
                         if( (enc28j60Read(EIR) & EIR_TXERIF) )
                               {
                                  enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRST);
                                  enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRST);
                                  enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, EIR, EIR_TXERIF); // Might be overkill but advised by Microchip Errata point 12, //MagKas 2014-10-25
                               }
                      

                      Thanks again!

                      1 Reply Last reply
                      0
                      • amoarg69A Offline
                        amoarg69A Offline
                        amoarg69
                        wrote on last edited by
                        #44

                        HI! Thanks for the topic! I'm new on this forum and I'm using enc28j60 with UIPE Lib. I have a lot of hang-up in my sketch.
                        Can somebody tell me wich is the best adapter-library combination to make a secure client-server arduno based sensor?
                        enc28j60 O WIZNET5100? UIPEEthernet, Ethercard or EtherShield ?

                        The solution proposed is modify enc28j60.cpp about line 215

                        Enc28J60Network::sendPacket(memhandle handle)
                        .....
                        if( (readReg(EIR) & EIR_TXERIF) )
                        {
                        writeOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRTS);
                        }
                        ...
                        }

                        by

                        if( (enc28j60Read(EIR) & EIR_TXERIF) )
                        {
                        enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRST);
                        enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRST);
                        enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, EIR, EIR_TXERIF);
                        }

                        It is correct???

                        Sorry for my English. Thanks again. Daniel

                        m26872M 1 Reply Last reply
                        0
                        • amoarg69A amoarg69

                          HI! Thanks for the topic! I'm new on this forum and I'm using enc28j60 with UIPE Lib. I have a lot of hang-up in my sketch.
                          Can somebody tell me wich is the best adapter-library combination to make a secure client-server arduno based sensor?
                          enc28j60 O WIZNET5100? UIPEEthernet, Ethercard or EtherShield ?

                          The solution proposed is modify enc28j60.cpp about line 215

                          Enc28J60Network::sendPacket(memhandle handle)
                          .....
                          if( (readReg(EIR) & EIR_TXERIF) )
                          {
                          writeOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRTS);
                          }
                          ...
                          }

                          by

                          if( (enc28j60Read(EIR) & EIR_TXERIF) )
                          {
                          enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRST);
                          enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRST);
                          enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, EIR, EIR_TXERIF);
                          }

                          It is correct???

                          Sorry for my English. Thanks again. Daniel

                          m26872M Offline
                          m26872M Offline
                          m26872
                          Hardware Contributor
                          wrote on last edited by
                          #45

                          @amoarg69 AFAIK the Enc28J60 has no stable setup yet. Use the W5100.

                          1 Reply Last reply
                          0
                          • amoarg69A Offline
                            amoarg69A Offline
                            amoarg69
                            wrote on last edited by
                            #46

                            @m26872 Thanks!
                            Wich library is better to use? UIPEthernet works well with W5100? I need a library that can handle client/server request.
                            Thanks very much!!!

                            m26872M 1 Reply Last reply
                            0
                            • amoarg69A amoarg69

                              @m26872 Thanks!
                              Wich library is better to use? UIPEthernet works well with W5100? I need a library that can handle client/server request.
                              Thanks very much!!!

                              m26872M Offline
                              m26872M Offline
                              m26872
                              Hardware Contributor
                              wrote on last edited by
                              #47

                              @amoarg69 W5100 is also the Arduino standard Ethernet shield and hence works good with the Arduino standard Ethernet lib. Server/client exemples provided through Arduino IDE for the lib.

                              1 Reply Last reply
                              1
                              • ggottaG Offline
                                ggottaG Offline
                                ggotta
                                wrote on last edited by
                                #48
                                This post is deleted!
                                1 Reply Last reply
                                0
                                • M Offline
                                  M Offline
                                  mhdayusuf
                                  wrote on last edited by
                                  #49

                                  I choose to reply to this very old topic because I updated to the latest UIPEthernet and this issue is still happening to me. I was about to replace it with a W5100 but came across this and tried it, compiled, uploaded, and here it goes. 24 hours of continuous web serving using an Arduino Mega 2560 and still counting!

                                  I wish this get incorporated into UIPEthernet

                                  Marcel STOICAM 1 Reply Last reply
                                  0
                                  • M mhdayusuf

                                    I choose to reply to this very old topic because I updated to the latest UIPEthernet and this issue is still happening to me. I was about to replace it with a W5100 but came across this and tried it, compiled, uploaded, and here it goes. 24 hours of continuous web serving using an Arduino Mega 2560 and still counting!

                                    I wish this get incorporated into UIPEthernet

                                    Marcel STOICAM Offline
                                    Marcel STOICAM Offline
                                    Marcel STOICA
                                    wrote on last edited by
                                    #50

                                    @mhdayusuf Do you have a copy of the changes you made? I am quite struggling to make it work and is not obvious to me what changes you made... Thanks.

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    15

                                    Online

                                    11.7k

                                    Users

                                    11.2k

                                    Topics

                                    113.1k

                                    Posts


                                    Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • MySensors
                                    • OpenHardware.io
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular