Enc28 and g80

It doesn’t work :frowning:

Hm, I thought it would work. I will doublecheck.

Doublechecked on the Cobra III. It works! I can assign 3 different MACs to the Enc28 and I can see on my router that the board is then registered with the assigned MAC.

Works for the Panda III (G80) as well.
Make sure by toggling the GPIOs with a little test program that you have assigned the right pins for the initialization. For the Panda III this works for me:

netif = new GHI.Networking.EthernetENC28J60(Microsoft.SPOT.Hardware.SPI.SPI_module.SPI2, FEZPandaIII.Gpio.D20, FEZPandaIII.Gpio.D21, FEZPandaIII.Gpio.D25);

I don’t understand wich are difference between running mode and debug mode.
If I use your code on visual studio in debug mode it works, but not in running mode, it still remain in reboot section due to not assigning mac address…

Ideas

Just noticed that I forgot a Thread.Sleep(200) after the instantiation of the networkinterface in the code I posted.
My original code it is:
//For Panda III
netif = new GHI.Networking.EthernetENC28J60(Microsoft.SPOT.Hardware.SPI.SPI_module.SPI2, FEZPandaIII.Gpio.D20, FEZPandaIII.Gpio.D21, FEZPandaIII.Gpio.D25);
Thread.Sleep(200);

In release mode the G80 code will run faster and perhaps the Enc28 is in this mode not ready with his initialization when the command to change the MAC arrives.

Find a way to make it working !!!
Pls help to integrate in firmware.

Only thing that permit good working is power on board, without visual studio in debug mode at this time network interface doesen’t reaply, after that open mfdeplo and send from plug-in menu – Reboot CLR.
After some seconds it starts to work with right mac address.

How can I create a code to do same thing from board???

Tks

a big sleep before you do stuff sounds like it should help. To me this screams of a power management issue, where the power to the chips isn’t settled before the chip is attempted to be initialised - so you could do something like a power management IC in your power train as well and get improvement

Tried a sleep up to 20 sec.
Now way…
Just with support of mfdeploy.

Ideas??

then figure out a way to restart CLR from code under certain circumstances - such that you don’t get into a reboot loop.

Could you suggest some code.
I’ve no idea on how to do it.

Tks

PowerState.RebootDevice(false);

is how you restart the device

As I said, you’d need to build your own logic into how you handle this so you didn’t permanently get into a loop. Perhaps set the MAC, if it doesn’t stick call the reboot. You’re the only one who has the problem (again, I wonder why that is) and you’re going to need to create a unique way of handing it

Works!!!
USed an external Sd card to manage flip flop file.
So I can manage memory of reboot, and it works.
100% time.
Sleepless night :wink: .
I don’t know way, I caheck schematic and there is no error on board so I don’t know about that problem.
Some hardware suggest on next board to produce to remove this problem.

Tks

1 Like

Glad to hear that you got it working. I’m interested to understand how you got it working but didn’t understand how you solved it. Can you please explain a little bit more?

{
namespace Test_Ethernet
{
public class Program
{
// #define DebugPrint
private static GHI.Networking.EthernetENC28J60 netif;
//private static bool _hasAddress;
//private static bool _available;
public static OutputPort LED,LED1;
public static bool reboot_sequnce;
public static string test;
public static FileStream FileHandle;

public static void Main()
{

LED = new OutputPort(GHI.Pins.G80.Gpio.PE8,false);
LED1 = new OutputPort(GHI.Pins.G80.Gpio.PE11, false);


SDCard sd_card = new SDCard();
sd_card.Mount();

bool fs_ready = false;
RemovableMedia.Insert += (a, b) =>
{
    fs_ready = true;
};
while (!fs_ready)
{
    System.Threading.Thread.Sleep(50);
}

//NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
// NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
//For Cobra III and ethernet ENC28 module on GXP Gadgeteer Bridge Socket 1 (SU)
string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
try {
FileHandle = new FileStream(rootDirectory +
@“\helld.txt”, FileMode.Open);
}
catch (Exception e)
{
Debug.Print(e.ToString());
//FileHandle = new FileStream(rootDirectory +@“\helld.txt”, FileMode.CreateNew);
}
netif = new GHI.Networking.EthernetENC28J60(Microsoft.SPOT.Hardware.SPI.SPI_module.SPI2, G80.Gpio.PC1,G80.Gpio.PE1,G80.Gpio.PC0);
Thread.Sleep(1000);
var myMac = new byte[] { 0x00, 0x21, 0x03, 0x00, 0x00, 0x09 }; //GenerateUniqueMacAddr.GenerateUniqueMacAddress(“Some unique string”);
var myMac_1 = new byte[] { 0x00, 0x21, 0x03, 0x00, 0x00, 0x02 };
byte[] data = new byte[100];
byte[] data1 = new byte[100];
try {
int read_count = FileHandle.Read(data, 0, data.Length);
Debug.Print(new string(Encoding.UTF8.GetChars(data), 0,
read_count));
Debug.Print(" ");
test = Encoding.UTF8.GetChars(data).ToString().Substring(1, 1);
}
catch (Exception e)
{
Debug.Print(e.ToString());
test = “”;
}

        if (test.Length == 0)
        {
            netif.PhysicalAddress = myMac;
            //FileHandle.Close();
            //File.Delete(rootDirectory + @"\helld.txt");
            FileHandle = new FileStream(rootDirectory +
                                      @"\helld.txt", FileMode.CreateNew);
            data1 = Encoding.UTF8.GetBytes("a");
            
            FileHandle.Write(data1, 0, data1.Length);
            FileHandle.Close();
            sd_card.Unmount();
            Thread.Sleep(500);
            PowerState.RebootDevice(true);
        }
        else
        {
            FileHandle.Close();
            File.Delete(rootDirectory + @"\helld.txt");
            if (VolumeInfo.GetVolumes()[0].IsFormatted)
            {
                
                string[] files = Directory.GetFiles(rootDirectory);
                string[] folders = Directory.GetDirectories(rootDirectory);

                Debug.Print("Files available on " + rootDirectory + ":");
                for (int i = 0; i < files.Length; i++)
                    Debug.Print(files[i]);

                Debug.Print("Folders available on " + rootDirectory + ":");
                for (int i = 0; i < folders.Length; i++)
                    Debug.Print(folders[i]);
            }
            sd_card.Unmount();
            
        }
       
        
        

/*
        if (reboot_sequnce == false)
        {
            reboot_sequnce = true;
            PowerState.RebootDevice(true);
        }
 */
        Thread.Sleep(2000);

/*
if (!GenerateUniqueMacAddr.ByteArrayEquals(netif.PhysicalAddress, myMac))
{
//update the Mac Address

            blink(100);
            
            //Hard Reboot the device so the newly Updated MAC is taking into consideration.
            PowerState.RebootDevice(false);
            
        }
  • */
    netif.Open();

           // for static IP
           netif.EnableStaticIP("192.168.15.71", "255.255.255.0", "192.168.15.6");
    
           netif.EnableStaticDns(new[] { "192.168.15.50" });
           blink(1000);
           Thread.Sleep(2000);
           //while (!_hasAddress || !_available)
           {
    

#if DebugPrint
Debug.Print(“Wait static IP”);
#endif
while(true){
LED1.Write(!LED1.Read());
Thread.Sleep(2000);
//PowerState.RebootDevice(false);
/*
if (GenerateUniqueMacAddr.ByteArrayEquals(netif.PhysicalAddress, myMac_1))
{
//update the Mac Address

                    blink(100);
                    PowerState.RebootDevice(false);
                    //Hard Reboot the device so the newly Updated MAC is taking into consideration.
                    
                }
                    */

                    }
            }

}
public static void blink(int freq)
{
LED.Write(true);
Thread.Sleep(freq);
LED.Write(false);
Thread.Sleep(freq);

    }

}

I’ve attached code, I’ve used an extetrnal sd card to store reboot flag.
Now I will use same SD to store ethernet address and some other things.