Main Site Documentation

FEZ COBRA II Net - cannot get Ethernet to work


#1

Good Day,

I have a new FEZ Cobra II Net board. I’ve updated it to the most recent bootloader and firmware. I am powering it with 5v externally for this testing.

My PC has the .NETMF 4.2 and 4.3 installed, as well as the GHI libraries.

I am using Visual Studio 12 Express on a Win 7 Home Premium 64-bit HP laptop.

Router is an Asus AC-66R dual band 802.11AC Gigabit Router. DHCP is enabled and working fine for laptops, iPads, etc. Ethernet cable tested and functional with other hardware.

No problems deploying functioning basic LED blinking type apps to the board. I am setting project properties to target .NETMF 4.2.

I am trying to determine if the ENC28J60 Ethernet port is functional. I cannot seem to get any sample code to work. My previous project used a Wiznet controller and a FEZ Panda II and worked perfectly. Now I am unable to get even a “Hello World” network app to function :’(.

I tried the below sample code from this site. Though the debug output indicated a simple server should be up on 10.0.1.25, that was not the case. Furthermore, I got the same cheerful output when I started with the Ethernet cable unplugged, and plugging/unplugging did not trigger any events. I also tried the “TestLanENC28J60” code with both static and DHCP, and neither worked.

Might anyone have a suggestion as to the most basic way I can ensure that this is not a hardware problem (bad controller)? Thank You!

Code:


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

namespace SimpleHttpServer
{
    public class Program
    {
        // use ENC28J60-based Ethernet connection
        static EthernetENC28J60 Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI2, GHI.Hardware.G120.Pin.P1_17, GHI.Hardware.G120.Pin.P2_21, GHI.Hardware.G120.Pin.P1_14, 4000);
       
        static byte[] outBuffer;
        static public ManualResetEvent NetworkAvailablityBlocking = null;
        static string myIP = "10.0.1.25";
 
        public static void Main()
        {
            Eth1.Open();

            NetworkInterfaceExtension.AssignNetworkingStackTo(Eth1);

            Eth1.CableConnectivityChanged += new EthernetENC28J60.CableConnectivityChangedEventHandler(Eth1_CableConnectivityChanged);
            Eth1.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Eth1_NetworkAddressChanged);

            Eth1.NetworkInterface.EnableStaticIP(myIP, "255.255.255.0", "10.0.1.1");

            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 (IPAddress.GetDefaultLocalAddress() == IPAddress.Any)
            {
                Debug.Print("IP address is not set yet.");
            }
            
            Debug.Print("IP address is set");

            string str = "Hello World!";
            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("------------------------------------------------------");
        }

        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);
        }
    }
}
   

#2

Can you confirm that the 10.x.x.x address is actually correct for your network ? Easy way to check is tell us IP address and subnet mask in use on your router.


#3

Oh yes, absolutely. The gateway is 10.0.1.1, subnet is 255.255.255.0 and the router assigned 10.0.1.221 to the Wiznet/panda II when I plugged it in just after. That device shows up in the router mgmt page, and I can ping it. Not so for the ENC28J60/Cobra II.

Thanks,

Scott


#4

SOLVED!

Clearly I’ve been away from this for too long . Stupid, stupid, stupid.

The CPU pins in the ENC28J60 instantiation are wrong :-[. I blindly used the ones from some example code, forgetting that the author used those for his device - apparently NOT the Cobra II.

I substituted the correct pins and voila - hello world!

Scott