Main Site Documentation

Cobra II and the ENC28


#1

Ok another dumb question…

I have the G120 board with built in Wifi. But I also want to have the ENC28 plugged in to.

I have read as many of the threads as I have found, and it looks like it shouldn’t be a problem, but I’m hitting a stumbling block right off the bat.

I have tried 2 things. The first thing I tried was just using the designer to attach the ENC to a socket. That worked to a point. But I don’t see how to assign the network stack to the ENC when done this way… For example, it would detect that the network cable had been unplugged, But it would not change the IP address. I “assumed” this was because I had not assigned the network stack to the ethernet adapter. But the “AssignNetworkingStackTo” seems to require the premium libs.

So then I read that I needed to use the Premium lib’s to do this. No problem I thought, found the example code on code share. Got everything setup but I ran into a wall understanding the one part of the code that I think that I need to make this work…

static EthernetENC28J60 eth1 = new EthernetENC28J60(add setting here);

Well I just don’t understand enough yet to pull these settings out of my southern orifice.

The “designer” let me plug the ENC into socket 6. But I don’t see a way to instantiate the ENC with “socket 6”. I’m sure it is some magical combination of “G120.pin X” but I have not been able to find that dumbed down to where my humble brain can grasp it.

So I guess I don’t really care which way I get it to work at this point. I just want to see a “Reply From…” when I connect the device to the network.

Thanks!

Dan


#2

no question is "dumb,’ I take “dumb question” to mean we need to enhance our documentation. Especially in the [em]just getting started department[/em]

I’m new here, so I honestly don’t know all the answers off my head; I’m answering what I can now, and will respond more after researching. If my answers are hitting below your level of expertise, let me know (I’m going to assume you’re at ground-zero on the learning curve (a tough spot!))…

One of the key pieces of using Designer that is easily missed is the auto-generated code file it produces “Program.generated.cs” that is where the visual information you’ve provided is used to create the objects and instantiate their connections in c#; you are relieved of performing those creation statements. (NOTE: if you try to do your coding of a gadgeteer device without using designer, i.e. working solely at the “NETMF” level; then, indeed, you will have to perform the initializations/instantiations etc. yourself.

Bottom line, the code:

will automatically be created for you in “Program.generated.cs”

If you haven’t already, you might want to skim through:

http://www.ghielectronics.com/docs/43/first-gadgeteer-project

I’ll respond more as I discover the answers myself…


#3

Since you have the Cobra II, you as well have the premium libraries. Include GHI.Premium.Net and add a using for it atop of Program.cs. There, you will be able to assign the networking stack to the ENC28, but remember, the networking stack can only be assigned a singular interface at a time, when you are done communicating through the ENC28, you will need to re-assign the wifi interface for it to continue working


#4

Thank you both for your responses!

But I’m looking for one level up in technical help…

What I’m looking for are the settings that I need to include in this line.

static EthernetENC28J60 eth1 = new EthernetENC28J60(add setting here); 

I’m trying to get it working on Socket 6. The designer lets me put it there but the designer doesn’t seem to use the “premium” libraries. It uses a different initialization that does not seem to support the “Add network Stack” method.

I found these magical settings for the built in wifi card, but have NO idea what they should be for the ENC plugged into socket 6?

Am I making sense?

Dan


#5

When I do as Jeff says, look at the Program.Generated.cs file of a new project that just has the Cobra II and ENC28 (Premium) device on the designer, connected at socket 6, I get:


            ethernet_ENC28 = new GTM.GHIElectronics.Ethernet_ENC28(6)

;

This is with the 4.2.9 firmware and SDK installed, in a 4.2 Gadgeteer project.

You should always go back and check what Intellisense says. To do that, you start typing this portion of the code:

        ethernet_ENC28 = new GTM.GHIElectronics.Ethernet_ENC28

And then when you type the open bracket, Intellisense tells you what options you need. That way, you can actually describe what you think you’re missing to us as well ! :slight_smile:


#6

the gadgeteer code snippet I used is:

using System;
using System.Net;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.Net.NetworkInformation;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

using GHI.Premium.Net;

// jeff Notes - had to add namespace:
//  Microsoft.SPOT.Net.NetworkInformation
//  System.Net (for IPAddress)
//
// had to add assemblies:
// GHI.Premium.{IO,Hardware,System}
// Gadgeteer & Gadgeteer.SPI
// System.Net.Security
//

namespace GadgeteerApp1
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            InitializeNetwork_Dhcp();
        }

        private void InitializeNetwork_Dhcp()
        {
            try
            {

                ethernet_ENC28.Interface.NetworkAddressChanged += new NetworkInterfaceExtension.NetworkAddressChangedEventHandler(Interface_NetworkAddressChanged);
                if (!ethernet_ENC28.Interface.IsOpen)
                {
                    ethernet_ENC28.Interface.Open();
                }
                ethernet_ENC28.Interface.NetworkInterface.EnableDhcp();
                
                NetworkInterfaceExtension.AssignNetworkingStackTo(ethernet_ENC28.Interface);
                 
            }
            catch (Exception exception)
            {
                Debug.Print("exception occurred, exception=" + exception.Message);
            }
        }

        void Interface_NetworkAddressChanged(object sender, EventArgs e)
        {
             Debug.Print("addr changed to: " + ethernet_ENC28.Interface.NetworkInterface.IPAddress);
        }

    }
}

this doesn’t answer the settings question for “new EthernetENC28J60(…)” but does show the use of AssignNetWorkingStackTo() which will be necessary to switch between the builtin WiFi and the externally added ENC28. Other threads with example code related to the issue that only one interface can be active at a time are:

http://www.ghielectronics.com/community/forum/topic?id=9845&page=1
http://www.tinyclr.com/codeshare/entry/615
https://www.ghielectronics.com/community/codeshare/entry/588

the answer to your question regards args to …ENC28J60… is more complicated (one of the reasons to stay at the Gadgeteer level of programming if you can). That said, the arguments are to establish SPI bus communications with the module (you can look at the source code while reading my explanation ( http://gadgeteer.codeplex.com/SourceControl/changeset/view/28532#334021 ) )
The first pin number is SPI chip-select and is gadgeteer socket pin #6, 2nd arg is SPI external-interrupt which is on gadgeteer socket pin #3, and finally the 3rd arg is SPI RESET which is on gadgeteer socket pin #4. Okay, that’s half the story: which pins and which socket (you mentioned you were using socket #6 on a Cobra II). The trick is to map those gadgeteer socket/pin numbers to actual CPU pin numbers which is the job of the schematic (http://www.ghielectronics.com/downloads/schematic/FEZ_Cobra_II_SCH.pdf) I come up with pins 34,70, and 33 respectively. If you have trouble with the mapping between socket+Pin to CPU-pin, have a read: http://www.ghielectronics.com/docs/6/locating-ios

Hope this helps


#7

Wow thank you very much for the detailed response!!!

It leads me to one question (so far)…

It looked to me like in I “had” to use the premium libraries (GHI.Premium.Net.) for my network modules if I wanted to be able to switch between them. So doesn’t that mean I can’t use the “designer” instantiated objects for the ENC? That I do have to go ahead and “take it to the next level” as it were? Or am I missing something?

Dan