Cannot reset the ENC28 using the RESET pin

With this code I was able to reset the ENC28 with no exception, but the first time I called Socket.Accept(), I got this exception:

2014/09/08 12:15:30.740 SocketServer.ProcessServer( tcp port = 8005 ): starting Socket.Accept()
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (17) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::poll [IP: 0000] ####
#### System.Net.Sockets.Socket::Poll [IP: 0011] ####
#### System.Net.Sockets.Socket::Accept [IP: 0017] ####
#### SocketServer.TCPServer::ProcessServer [IP: 0068] ####
#### SocketException ErrorCode = 10050
#### SocketException ErrorCode = 10050
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10050
#### SocketException ErrorCode = 10050


  try
            {
                eth = new GHINET.EthernetENC28J60(SPI.SPI_module.SPI1, G400.PA28, G400.PB1, Cpu.Pin.GPIO_NONE);  //Used by Raptor ENC28 ethernet module in socket 3

                Thread.Sleep(100);
                eth.Dispose();
                Debug.GC(true);
                Thread.Sleep(100);
                OutputPort reset = new OutputPort(G400.PC23, true);
                reset.Write(false);
                Thread.Sleep(20);
                reset.Write(true);

                reset.Dispose();
                Debug.GC(true);
                eth = new GHINET.EthernetENC28J60(SPI.SPI_module.SPI1, G400.PA28, G400.PB1, Cpu.Pin.GPIO_NONE);  //Used by Raptor ENC28 ethernet module in socket 3
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
            }


@ dspacek -

I don’t think that exception is related to Reset pin.

Why do you need to control the reset pin manually?

When you create an interface object, the driver calls reset for you.

Because I am having the same problem on the Raptor with MF 4.3 that PhilM was having with the Cobra, Socket.Accept() locks up and never returns, so no TCP connections can be made. You suggested a work-around to this problem here:

https://www.ghielectronics.com/community/forum/topic?id=12342&page=14

With this code:


private void listen()
         {
             bool doSleep = false;
  
  
             while (true)
             {
                 Debug.GC(true);
                 try {
                     bool poll= false;
                     try
                     {
                         poll = mServer.Poll(15 * 1000 * 1000, SelectMode.SelectRead);
                     }
                     catch
                     {
                         poll = false;
                     }
                     if (poll == true)
                     {
                         Program.led.Write(true);
                         Socket newClient = mServer.Accept();
                         ProcessRequest(newClient);
                         Program.led.Write(false);
                     }
                     else
                     {
                         // Reset ENC28 by Reset pin here
                     }
                     doSleep = false;
                 } catch {
                     doSleep = true;
                 }
                 if (doSleep) {
                     try {
                         Thread.Sleep(5000);
                     } catch { }
                 }
             }
         }

@ dspacek -

Hello,

  • Did you try to use “ExecutionConstraint.Install”? This is better way for your problem.
  • Or you can create a wrapper class, put Accept() in a new thread and you can stop any time.

About the reset pin ENC, I think this is for another issue. if I remember correctly, after working for long time, ENC stop responding. And it depended on router/switch, just few of them have this issue. Reset the pin was used for this case. But after we improved the ENC28 driver in 4.2, this way is no longer to use.

In 4.3 we use same driver with 4.2 that included these improvement. But we may take a look in that again.

In case you still want to reset the ENC, just pull the reset pin low-high. Don’t reset whole ENC object. If you reset whole enc28, you need to open and initialize everything again. And depends on code, just reset this pin in case error happens. No meaning when you reset then create enc28 object.

For easier and faster for us (and you), can you please post a very simple code for us to reproduce your problem?

We can write a simple code that use Accept() but we know you won’t happy if we say: “Can not reproduce” :smiley: . That is why we usually need exactly user’s code.

Yes, I tried “ExecutionConstraint.Install”, it did not work. Please see my post:
“Connect() and Accept() can sometimes hang forever”
https://www.ghielectronics.com/community/forum/topic?id=16565&page=2
I tried to create a wrapper class, put Accept() in a new thread, it did not work. Please see my post:
https://www.ghielectronics.com/community/forum/topic?id=16565&page=2
I posted the code I was trying. In this thread I posted the code I was using to try to reset the ENC28.
I don’t really want to reset the ENC28, what I really want is for Socket.Accept() to not freeze and never return.

If you wish, I will post the code for my socket server. You can run that and use the stress tester to show how Accept() locks up. The stress tester is here:
https://www.ghielectronics.com/community/codeshare/entry/780

Please let me know if you will help with this.