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