Enc28 and g80

I’ve a strange problem during enc finalization.
If I leave unsettled the physical address using standard store on enc it works perfectly. When I try to setup physical address on interface sometimes works and sometimes not.
It’s very strange.
I’ve last firmware on g80 downladed for ghi directory.
Netmf is 4.3.1

idea???
Getting crazy this thing.

I assume you mean an initialization problem?

By physical address do you mean the MAC or IP address?

Please show us your code.

Problem is very strange when I use debugger and start code Mac address is assigned. When I power on it takes always same Mac address.
I really don’t understand why.
I’ve tried to insert a sleep between parameters and open and. But doesn’t solve anything.

Ideas ???

try doing the open before setting MAC and IP addresses.

http://old.ghielectronics.com/docs/30/networking#3123

Before this solution I tested open before parameters but it doesn’t work.
It takes correct ip but no Mac address.
As I told to you strange thing is using debug it works!!! Only when I apply power it doesn’t work.

Pls suggest me solution.

Have you tried setting the MAC address with FEZConfig?

No just using my deploy I will test tooday

Why it works with debug and not without debug???
It’s same code.

timing.
Not saying that this is a good thing or not, but that’s what the difference is going to be.

You could also try a sleep before you initialize the network…

Tryed this too but even if I call a sleep of 5 sec befor network inizialization it doesn’t work.

Ideas

Have you tried to use FEZConfig to set the MAC address?

How did you get the MAC address you are trying to use? Try a different MAC address from a MAC address generator.

I’ve tried to insert other Mac just adding one to the last byte.
Fez config doesn’t recognize external enc28.
I can try to generate from so other service Mac address. Only rhat thing i didnt tryied.

Tomorrow morning I will try.

changing the last byte is not going to alter the validity of a MAC if there’s something on the network (eg a switch or router) that has strict manufacturer checking policies. Make sure you use a random MAC generator that gives a completely different address.

I’ve tried more all less all thing.
I discover problem on timing.
For some strange reason during debug it runs a little bit slower and can assign correctly Mac address.
When it works with power supply without debug goes wrong.
I think that bug is on spi bus.
That’s because I’ve tried to read ys8ng spot l8bryry of Microsoft Mac address and without using a sleep next to read Mac address was not completely right some bit swap.
Very strange thing.

Ideas ???

I can confirm that problem is a bug on enc28 driver on 4.3.8 firmware of g80.

IDEAS???
Downgrade?

ok, I’ll bite. How do you confirm it’s a bug on 4.3.8?

Tested an empty program just with initialization of Ethernet using ghi driver and it works every time just during debug.
When we run without debug it doesn’t work.
So we wrote using enc28 datasheet a small driver just to setup Mac and it works in debug and running mode.
We have tried to use that part of code to initialize enc28 and after that use ghi driver but it’s not possible we lose Mac always.

Ideas

Did you consider to reboot the board after changing the MAC?
Here is the code I actually use. I hope that it works.

#define DebugPrint
private static GHI.Networking.EthernetENC28J60 netif;
private static bool _hasAddress;
private static bool _available;

public static void Main()
{
....
NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
            NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;
            //For Cobra III and ethernet ENC28 module on GXP Gadgeteer Bridge Socket 1 (SU)
            netif = new GHI.Networking.EthernetENC28J60(Microsoft.SPOT.Hardware.SPI.SPI_module.SPI2, G120.P0_5, G120.P0_4, G120.P4_28);
            // Edit: evtl. here Thread.Sleep(200);
            Thread.Sleep(200);
            var myMac = GenerateUniqueMacAddr.GenerateUniqueMacAddress("Some unique string");                
            if (!GenerateUniqueMacAddr.ByteArrayEquals(netif.PhysicalAddress, myMac))
            {
                //update the Mac Address
                netif.PhysicalAddress = myMac;
                //Hard Reboot the device so the newly Updated MAC is taking into consideration.
                PowerState.RebootDevice(false);
            }
            netif.Open();              
            EthENCJ28 = new EthENCJ28_Device(netif);
            if (useDHCP)
            {
                // for DHCP 
                netif.EnableDhcp();
                netif.EnableDynamicDns();
                while (netif.IPAddress == "0.0.0.0")
                {
#if DebugPrint
                    Debug.Print("Wait DHCP");
#endif
                    Thread.Sleep(300);
                }
                _hasAddress = true;
#if DebugPrint
                Debug.Print("IP is: " + netif.IPAddress);
#endif
            }
            else
            {
                // for static IP
                netif.EnableStaticIP(DeviceIpAddress, SubnetMask, GateWayIpAddress);
                netif.EnableStaticDns(new[] { DnsServerIpAddress });
                while (!_hasAddress || !_available)
                {
#if DebugPrint
                    Debug.Print("Wait static IP");
#endif
                    Thread.Sleep(100);
                }
            }
}
        {

   static void NetworkChange_NetworkAddressChanged(object sender, EventArgs e)
        {
            Debug.Print("The network address has changed.");
            _hasAddress = netif.IPAddress != "0.0.0.0";
            Debug.Print("IP is: " + netif.IPAddress);
           
            Thread.Sleep(20); 
        }


  static void NetworkChange_NetworkAvailabilityChanged(object sender,        NetworkAvailabilityEventArgs e)
        {
            //Debug.Print("Network available: " + e.IsAvailable.ToString());

            _available = e.IsAvailable;
        }


// This code is from Unique and Valid MAC Address Generator  by Jay Jay
// https://www.ghielectronics.com/community/codeshare/entry/822

using System;
using Microsoft.SPOT;
namespace RoSchmi.Net.Divers
{
 static class GenerateUniqueMacAddr
{
    /// <summary>
    /// Generates a Unique MAC Address based on a a hashcode
    /// 
    /// </summary>
    /// <param name="myUniqueId"></param>
     /// <returns></returns>
      public static byte[] GenerateUniqueMacAddress(object myUniqueId = null)
    {
        //great article explaining the making of the MAC Address first Byte...
        //http://packetsdropped.wordpress.com/2011/01/13/mac-address-universally-or-locally-administered-bit-and-individualgroup-bit/

        // create a en empty byte array
        var myMac = new byte[6];
        //generate a random based on a fixed seed this will guarantee that we get the 
        //same Random number everytime based on the provided string... make your string UNIQUE...
        //This would be great if only each board had a UNIQUE SERIAL NUmber ahhhhhh...          
        var r = myUniqueId != null ? new Random(myUniqueId.GetHashCode()) : new Random();
        // fill the newly generated bytes into the variable
        r.NextBytes(myMac);
        // update the last bit of the first byte with 1 which will flg the Mac as a Locally administered Mac address...
        //Please share if you have a better way of doing this.
        myMac[0] = (byte)(myMac[0] | 0x01);
        //shift to the left by 1 which will give 10 on the last two bits of the first byte... 0 on the last bit means UNICAST Mac Address.
        myMac[0] = (byte)(myMac[0] << 1);
        return myMac;
    }
    //returns true if the two byte arrays are equal
    public static bool ByteArrayEquals(byte[] a1, byte[] a2)
    {
        if (a1 == a2)
        {
            return true;
        }
        if ((a1 != null) && (a2 != null))
        {
            if (a1.Length != a2.Length)
            {
                return false;
            }
            for (int i = 0; i < a1.Length; i++)
            {
                if (a1[i] != a2[i])
                {
                    return false;
                }
            }
            return true;
        }
        return false;
    }
}
}
1 Like

ok, so it’s not a bug on 4.3.8, it appears to be a bug across the board. I think it’s now time to ask again why nobody else sees this but you do?

G80 is a GHI chip/firmware, so if there’s a fault (and it’s been fixed in 4.4 - you’d need to look, there were changes to those fi) then you might need to look at how you can get updated code - GHI have said they aren’t working on 4.4 releases, and have moved their effort to TinyCLR OS. You probably just need to find a workaround (implement your own MAC setting code before netmf gets to it?)