Wi-Fi bad: SC20260N module

What am i doing wrong. It is same as the example code. I recheck the wiring, it all looks good. Please help

Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1)

#### Message: 
#### GHIElectronics.TinyCLR.Devices.Network.Provider.NetworkControllerApiWrapper::Enable [IP: 0000] ####
#### GHIElectronics.TinyCLR.Devices.Network.NetworkController::Enable [IP: 0007] ####
#### SCTouch.WiFiInterface::Init [IP: 0123] ####
#### SCTouch.Program::Main [IP: 0067] ####
        public static void Init()
        {
            try
            {
                // Wifi setting
                var wifiSettings = new WiFiNetworkInterfaceSettings()
                {
                    Ssid = "...",
                    Password = "...",
                }; 

                var enablePinNumber = SC20260.GpioPin.PC0;
                var chipSelectPinNumber = SC20260.GpioPin.PH6;
                var irqPinNumber = SC20260.GpioPin.PF10;
                var resetPinNumber = SC20260.GpioPin.PC3;

                var spiControllerName = SC20260.SpiBus.Spi3;
                var gpioControllerName = SC20260.GpioPin.Id;

                var enablePin = GpioController.GetDefault().OpenPin(enablePinNumber);
                enablePin.SetDriveMode(GpioPinDriveMode.Output);
                enablePin.Write(GpioPinValue.High);

                SpiNetworkCommunicationInterfaceSettings netInterfaceSettings =
                        new SpiNetworkCommunicationInterfaceSettings();

                var chipselect = GpioController.GetDefault().OpenPin(chipSelectPinNumber);

                var settings = new SpiConnectionSettings()
                {
                    ChipSelectLine = chipselect,
                    ClockFrequency = 4000000,//4
                    Mode = SpiMode.Mode0,
                    ChipSelectType = SpiChipSelectType.Gpio,
                    ChipSelectHoldTime = TimeSpan.FromTicks(10),
                    ChipSelectSetupTime = TimeSpan.FromTicks(10)
                };

                // netInterfaceSettings
                netInterfaceSettings.SpiApiName = spiControllerName;
                netInterfaceSettings.SpiSettings = settings;

                netInterfaceSettings.GpioApiName = gpioControllerName;

                netInterfaceSettings.InterruptPin = GpioController.GetDefault().OpenPin(irqPinNumber);
                netInterfaceSettings.InterruptEdge = GpioPinEdge.FallingEdge;
                netInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;

                netInterfaceSettings.ResetPin = GpioController.GetDefault().OpenPin(resetPinNumber);
                netInterfaceSettings.ResetActiveState = GpioPinValue.Low;

                if (false)
                {
                    wifiSettings.Address = new IPAddress(new byte[] { 192, 168, 1, 31 });
                    wifiSettings.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 });
                    wifiSettings.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 });
                    wifiSettings.DnsAddresses = new IPAddress[] { new IPAddress(new byte[]
                    { 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) };

                    wifiSettings.MacAddress = new byte[] { 0x00, 0x5, 0x00, 0x00, 0x00, 0x00 };
                }

                wifiSettings.DhcpEnable = Network_DHCP;
                wifiSettings.DynamicDnsEnable = true;

                var networkController = NetworkController.FromName(SC20260.NetworkController.ATWinc15x0);
                //var networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.ATWINC15xx.NetworkController");

                networkController.SetInterfaceSettings(wifiSettings);
                networkController.SetCommunicationInterfaceSettings(netInterfaceSettings);
                networkController.SetAsDefaultController();

                networkController.NetworkAddressChanged += NetworkController_NetworkAddressChanged;

                networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged;

                networkController.Enable();

                DispPrint("WiFi Initialized");

                // Network is ready to use
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception ex)
            {
                DispPrint(ex.Message);
                DispPrint("WiFi bad");
                Thread.Sleep(1000);
            }
        }

        private static void NetworkController_NetworkAddressChanged
            (NetworkController sender, NetworkAddressChangedEventArgs e)
        {

            var ipProperties = sender.GetIPProperties();
            var address = ipProperties.Address.GetAddressBytes();

            WiFiLinkReady = address[0] != 0;
            Network_IP = "";

            if (WiFiLinkReady)
            {
                Network_IP = address[0] + "." + address[1] + "." + address[2] + "." + address[3];

            }
        }

        private static void NetworkController_NetworkLinkConnectedChanged
                (NetworkController sender, NetworkLinkConnectedChangedEventArgs e)
        {
            // Raise event connect/disconnect
            Program.DB_Print("NetworkController_NetworkLinkConnectedChanged");
        }

Example: WiFi
Does any one have this working

This line generated the exception
networkController.Enable();

Is this a custom board? I have the same issue and have been unable to track it down. All the connections are good and correct assignments but it still throws an exception. The same code on a GHI dev board works with different IO assignments so it must be hardware related but I’ve not been able to track it down yet.

Hi, the example uses wifi 7 click. If you use different module (same WINC15xx), make sure it is SPI mode, not AT mode.

And if all connections are good, you may need to verify all single pins, make sure they connected to mcu as well.

Example, PC0 is connected to enable pin, but somehow MCU cannot control PC0. Try to toggle all these pins, include SPI pins make sure they are connecting to MCU.

Last, make sure chipselect and irq pins are not used anywhere else in project.

Could you try change interrupt pin (PF10) to different pin? Any other interrupt used in your project with PA10, PB10, PC10…any pins end with index number 10?

Thanks Dat, we are using WINC15xx and reviewed the “wifi 7 click” schematic so we have the same pullups and connections.
To address the issue Dave highlighted - we are using the same pins as per the example code now; but nothing helped.
Dat: Can you try the latest GHI library, may be there is some regression

            var enablePinNumber = SC20260.GpioPin.PA8;//PC0
            var chipSelectPinNumber = SC20260.GpioPin.PA6;//PH6
            var irqPinNumber = SC20260.GpioPin.PF10;
            var resetPinNumber = SC20260.GpioPin.PC3;

            var spiControllerName = SC20260.SpiBus.Spi3;
            var gpioControllerName = SC20260.GpioPin.Id;

The interrupt pin is PF10, do you use any interrupt pin with index 10 somewhere else?

It will not work if somewhere else you use any of these pins: PA10, PB10, PC10… PZ10 as interrupt.

Does it work when you change those pins?

Thanks Dat,
I do not have any pins PA10, PB10, PC10… PZ10 as interrupts

Couple of them I use but as GPIO - Input and Output

Hi I tried 2.2.0.5000 which is official latest library.

We tried your code nothing changed except for one thing, we don’t have PH6 exposed, so we use PH7 for chipselect.

We use GHI SC202600 Dev board + 7 click wifi.

Everything works good for us. I think something wrong with custom board and custom wifi.

If you have our SC20260 Dev + 7Click you should try it.

Keep in mind that we don’t support hidden SSID, and the password is correct.

Below is our wifi schematic that you can reference.

…unfortunately you are reminding me of my past.
Just a questions, what firmware does the ATWINC have ?

I think 19.5.4.xxx.

If you have 19.6.xxx then it could be the problem

I had 10 ATWINC 19.5.2 and I guarantee that by switching them to 19.7.6.19389 everything started working correctly… maybe it’s time to check if updating to latest FW via UART can fix it.

1 Like