ENC28 with G120HDR V2.0

Hi,
Trying to test ENC28 with G120HDR V2.0

When i make blue led blink, i can deploy and run the project witout any problem.

Adding some code to test the ENC28 1.1 module, i am not sure about the socket but it seems that SPI socket is wired to SPI2 (it will perfet to have a detailed spec of the HDR V2 pinout).

When i try to run the code the debbuger is going to Eth1.Open(); and then hangs. Futher i can reset the G120HDR but it seems to jump into an infinite loop, and the only way to make it alive again is to reload the firmware.

It seems that i have missed something.

Here is the code, running with .Net framework 4.2 , G120 with 02/14/13 Firmware

regards
Loïc

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Net;
using System.Threading;
using GHI.Premium.Net;
using System.Text;
using System.Net;
using GHI.Premium.Hardware;

namespace Test_Application1
{

    public class Program
    {
        static OutputPort output;

        static Timer stateTimer;

        static EthernetENC28J60 Eth1;

        // if you were to use ENC28J60-based Ethernet connection16.        
        //static EthernetENC28J60 Eth1 = new EthernetENC28J60(add code here to configure it);
        // wifi is same thing18.        
        // static WiFiRS9110 wifi = new WiFiRS9110(......);

        static byte[] outBuffer;
        static public ManualResetEvent NetworkAvailablityBlocking = null;
        static public ManualResetEvent IPAddressSetResetEvent = null;
        static string myIP = "192.168.240.166";

        public static void Main()
        {

            Debug.Print("Test");

            output = new OutputPort(GHI.Premium.Hardware.G120.Pin.P1_5, false);

            //---- timer tick
            TimerCallback timerDelegate = new TimerCallback(TimerTick);
            AutoResetEvent autoEvent = new AutoResetEvent(false);
            stateTimer = new Timer(timerDelegate, autoEvent, 400, 171);


            //----  timer tick1 for a nice effect frequency  blinking blue led
            TimerCallback timerDelegate1 = new TimerCallback(TimerTick1);
            AutoResetEvent autoEvent1 = new AutoResetEvent(false);
            stateTimer = new Timer(timerDelegate1, autoEvent1, 500, 175);

            //--- Some sample grabed on the net, hope the GPIO pin are ok 
            Eth1 = new  EthernetENC28J60(SPI.SPI_module.SPI2,  G120.Pin.P1_9, G120.Pin.P2_4,  G120.Pin.GPIO_NONE);

           InitHttp();

            while (true)
            {
                Thread.Sleep(12500);
            }
        }

        static public void TimerTick(Object stateInfo)
        {

            // TODO: Do Timer Tick stuff here...

            output.Write(!output.Read());


        }


        static public void TimerTick1(Object stateInfo)
        {

            // TODO: Do Timer Tick stuff here...

            output.Write(!output.Read());
        }


        public static void InitHttp()
        {
            Eth1.Open();   // its hanging here ...

            NetworkInterfaceExtension.AssignNetworkingStackTo(Eth1);
            Eth1.NetworkInterface.EnableStaticIP(myIP, "255.255.255.0", "192.168.240.2");

            //Eth1.NetworkInterface.EnableDhcp();
            IPAddressSetResetEvent = new ManualResetEvent(false);
            Eth1.CableConnectivityChanged += new EthernetENC28J60.CableConnectivityChangedEventHandler(Eth1_CableConnectivityChanged);
            Eth1.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Eth1_NetworkAddressChanged);
            if (!Eth1.IsCableConnected)
            {
                NetworkAvailablityBlocking = new ManualResetEvent(false);
                do
                {
                    if (!Eth1.IsCableConnected)
                    {
                        Debug.Print("Ethernet cable is not connected yet.");
                    }
                    else
                        break;
                } while (!NetworkAvailablityBlocking.WaitOne(5000, false));
            }
            while (!IPAddressSetResetEvent.WaitOne(500, false))
            {
                Debug.Print("IP address is not set yet.");
            }
            Debug.Print("IP address is set");
            string str = Resources.GetString(Resources.StringResources.String1);
            outBuffer = Encoding.UTF8.GetBytes(str);
            try
            {
                Debug.Print("Running HttpServer");
                Debug.Print("Type this IP address to access the webpage: " + Eth1.NetworkInterface.IPAddress);
                RunServer();
            }
            catch (Exception e)
            {
                Debug.Print(e.Message);
            }
        }
        static void Eth1_CableConnectivityChanged(object sender, EthernetENC28J60.CableConnectivityEventArgs e)
        {
            Debug.Print("Built-in Ethernet Cable is " + (e.IsConnected ? "Connected!" : "Disconneced!"));
            if (e.IsConnected)
                NetworkAvailablityBlocking.Set();
        }
        static void Eth1_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("New address for The built-in Ethernet Network Interface ");

            Debug.Print("Is DhCp enabled: " + Eth1.NetworkInterface.IsDhcpEnabled);
            Debug.Print("Is DynamicDnsEnabled enabled: " + Eth1.NetworkInterface.IsDynamicDnsEnabled);
            Debug.Print("NetworkInterfaceType " + Eth1.NetworkInterface.NetworkInterfaceType);
            Debug.Print("Network settings:");
            Debug.Print("IP Address: " + Eth1.NetworkInterface.IPAddress);
            Debug.Print("Subnet Mask: " + Eth1.NetworkInterface.SubnetMask);
            Debug.Print("Default Getway: " + Eth1.NetworkInterface.GatewayAddress);
            Debug.Print("Number of DNS servers:" + Eth1.NetworkInterface.DnsAddresses.Length);
            for (int i = 0; i < Eth1.NetworkInterface.DnsAddresses.Length; i++)
                Debug.Print("DNS Server " + i.ToString() + ":" + Eth1.NetworkInterface.DnsAddresses[i]);
            Debug.Print("------------------------------------------------------");
            if (Eth1.NetworkInterface.IPAddress == myIP || Eth1.NetworkInterface.IPAddress != "0.0.0.0")
                IPAddressSetResetEvent.Set();
        }
        internal static void RunServer()
        {
            HttpListener listener = new HttpListener("http");
            listener.Start();

            while (true)
            {
                HttpListenerResponse response = null;
                HttpListenerContext context = null;

                try
                {
                    context = listener.GetContext();

                    response = context.Response;
                    HttpListenerRequest request = context.Request;
                    switch (request.HttpMethod.ToUpper())
                    {
                        case "GET": ProcessClientGetRequest(context);
                            break;
                    }
                    if (response != null)
                    {
                        response.Close();
                    }
                }
                catch
                {
                    if (context != null)
                    {
                        context.Close();
                    }
                }
            }
        }
        private static void ProcessClientGetRequest(HttpListenerContext context)
        {
            HttpListenerRequest request = context.Request;
            HttpListenerResponse response = context.Response;
            Debug.Print(request.RawUrl);
            response.OutputStream.Write(outBuffer, 0, outBuffer.Length);
        }

    }
}

Yes, tried but unreadable like this …

@ Loic - Welcome! Or should I say “Welcome back”!

With that user id you must be the first user on this forum! :smiley:

Have you tried this example?

http://www.tinyclr.com/codeshare/entry/588

Yes,
The code is originated from your example, we have substituted



static EthernetENC28J60 Eth1 = new EthernetENC28J60(add code here to configure it); 

with this one 

 Eth1 = new  EthernetENC28J60(SPI.SPI_module.SPI2,  G120.Pin.P1_9, G120.Pin.P2_4,  G120.Pin.GPIO_NONE);

we have made some assumptions about the control pins lacking description of the SPI connector, and too lazy to follow the trace.

So instead of throwing exceptions we are running into a deadlock and have found no other way to reload the firmware. We have tried the code sample with to different cards with the same results.

Old-timer, we are transitioning from USBIzi to G120 ;=))

regards
Loïc

@ Loic -

Is also use the G120 with the ENC28 and here are the Pins I use to :

        Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI2, G120.Pin.P1_17, G120.Pin.P0_5, G120.Pin.P1_14);

Seems to be slightly different but works fine for me !

Thanks for your reply,

I am aware of the document. The indicated brochure doesnt describe the new cards : I own G120HDR 2.0 cards, which are different from the model described in the brochure.

  • the SPI connector is wired to SPI2, on contrary with the 1.0 you have to wire the different signals to one of the User Connectors to use ENC28.

  • It is stated that the ENC28 can accommodate the SPI connector, so SPI2 is the reserved SPI channel, but there is no trace in the documentation of the other signals of the SPI connector other than GPIO.

So before investigate my compiler setup, I am looking for the G120HDR 2.0 SPI connector specs, and if someone is using the G120HDR 2.0 with the ENC28 that can provide the initialization setup

Meanwhile, I will have a try with the line provided by LouisCpro, i can also wire a breakout module to identify 1_17, 0_5 and 1_14

 Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI2, G120.Pin.P1_17, G120.Pin.P0_5, G120.Pin.P1_14); 

regards
Loïc

I was speaking of the SPI connector present on V2 witch doesnt exist on V1

I suppose that the connector is a Type S connected to SPI2

Socket Type S
Serial peripheral interface (SPI). Pin 6 is the chip-select (CS) line, pin 7 is the master-out/slave-in (MOSI) line, pin 8 is the master-in/slave-out (MISO) line, and pin 9 is the clock (SCK) line. In addition, pins 3, 4 and 5 are general-purpose input/outputs, with pin 3 supporting interrupt capabilities.
Pinout
Pin 1 Pin 2 Pin 3 Pin 4 Pin 5 Pin 6 Pin 7 Pin 8 Pin 9 Pin 10
+3.3V +5V GPIO! GPIO GPIO CS MOSI MISO SCK GND

but i need to map the GPIO pins to

 Eth1 = new EthernetENC28J60  

regards
Loïc

@ Loic -

Have a look on this thread : http://www.tinyclr.com/forum/topic?id=10818

This are the several socket assignments I use, and all works fine !

Thanks Louis

That was exactly what I was looking for, I have done some crosscheck and it fullfill exactly the pinout , and now its fixed with the line as you stated.


 static EthernetENC28J60 Eth1  = new EthernetENC28J60(SPI.SPI_module.SPI2, G120.Pin.P1_17, G120.Pin.P0_5, G120.Pin.P1_14);

regards
Loïc

ENC28
PIN GADGETEER / PIN G120 / FUNCTION ENC28
3V3 / 3V3 / -
5V / 5V / -
P3 / P0.5 / INT
P4 / P1.14 / RESET
P5 / P1.16 / WOL
P6 / P1.17 / CS
P7 / MOSI2 / SI
P8 / MISO2 / SO
P9 / SCK2 / SCK
GND / GND / -

You’re welcome Loic !

Do not hesitate to check the answer…

@ andre.m - Nowhere, but a difference with what Loic assigned in its previous post to us !

Hi,
The wiki was Ok concerning the point : How to use ENC28 on G120HDR Board

but it wasnt clear for me as i am using the G120HDR 2.0 with the dedicated SPI connector.

regards
Loïc

no clue about V2.0

• By soldering the correct wires to the user socket or;
• by using the extender or breakout board with headers and connecting the wires to headers on the G120HDR board.

The information has been added to the wiki regarding the SPI socket. The information can be found here at the end of this section: http://wiki.tinyclr.com/index.php?title=G120HDR_Developer#Gadgeteer_note