Hi all,
I’m new to TinyClr and have first my experiences with FEZ.Bit using WiFi connection. That all works very well out of the box.
Now I’ve tried to port the code to a FEZ.Feather board. Using the same code I only changed the GPIO- and SPI definitions from FEZBit to FEZFeather. (I’ve also tried both SPI on Feather)
Definitions are for FEZ.Bit:
//Setup Pins
var enablePinNumber = FEZBit.GpioPin.WiFiEnable;
var chipSelectPinNumber = FEZBit.GpioPin.WiFiChipselect;
var irqPinNumber = FEZBit.GpioPin.WiFiInterrupt;
var resetPinNumber = FEZBit.GpioPin.WiFiReset;
var spiControllerName = FEZBit.SpiBus.WiFi;
and for FEZ.Feather:
//Setup Pins
var enablePinNumber = FEZFeather.GpioPin.WiFiEnable;
var chipSelectPinNumber = FEZFeather.GpioPin.WiFiChipselect;
var irqPinNumber = FEZFeather.GpioPin.WiFiInterrupt;
var resetPinNumber = FEZFeather.GpioPin.WiFiReset;
var spiControllerName = FEZFeather.SpiBus.Spi4;
On the FEZ.Feather calling networkController.Enable() throws a System.InvalidOperationException.
(An unhandled exception of type ‘System.InvalidOperationException’ occurred in GHIElectronics.TinyCLR.Devices.Network.dll)
As said, on FEZ.Bit all is working as expected.
Both boards are 2.2.0.6500; Visual Studio 2022 on W10 Enterprise.
Please can give anyone an advice what I’m doing wrong?
Thanks in advance
Greetings Juerg
FEZ.Feather-Code (non-working):
using System;
using System.Diagnostics;
using System.Net;
using System.Threading;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Network;
using GHIElectronics.TinyCLR.Devices.Spi;
using GHIElectronics.TinyCLR.Pins;
namespace FEZ.Feather_Wifi_Test
{
internal class Program
{
static string ssid = "mySSID";
static string pw = "myPW";
private static readonly NetworkController networkController = NetworkController.FromName
(SC20100.NetworkController.ATWinc15x0);
private static void Main()
{
// Wifi
InitWifiModule();
WiFiNetworkInterfaceSettings networkSettings = new WiFiNetworkInterfaceSettings
{
Ssid = ssid,
Password = pw,
DhcpEnable = true,
DynamicDnsEnable = true
};
networkController.SetInterfaceSettings(networkSettings);
networkController.SetAsDefaultController();
//Wait for IP address
var isReady = false;
networkController.NetworkAddressChanged += (a, b) =>
{
var ipProperties = a.GetIPProperties();
Debug.WriteLine("IP: " + ipProperties.Address);
var address = ipProperties.Address.GetAddressBytes();
if (address[0] != 0 && address[1] != 0)
isReady = true;
};
Debug.WriteLine("Enable the network controller.");
networkController.Enable();
Debug.WriteLine("Network controller is enabled.");
while (!isReady)
Thread.Sleep(100);
IPHostEntry ip = Dns.GetHostEntry("branscheid-gmbh.com");
Debug.WriteLine("BIA' IP = " + ip.AddressList[0].ToString());
Thread.Sleep(Timeout.Infinite);
}
private static void InitWifiModule()
{
//Setup Pins
var enablePinNumber = FEZFeather.GpioPin.WiFiEnable;
var chipSelectPinNumber = FEZFeather.GpioPin.WiFiChipselect;
var irqPinNumber = FEZFeather.GpioPin.WiFiInterrupt;
var resetPinNumber = FEZFeather.GpioPin.WiFiReset;
var spiControllerName = FEZFeather.SpiBus.Spi4;
var gpio = GpioController.GetDefault();
var enablePin = gpio.OpenPin(enablePinNumber);
enablePin.SetDriveMode(GpioPinDriveMode.Output);
enablePin.Write(GpioPinValue.High);
SpiNetworkCommunicationInterfaceSettings netInterfaceSettings =
new SpiNetworkCommunicationInterfaceSettings();
var settings = new SpiConnectionSettings()
{
ChipSelectLine = gpio.OpenPin(chipSelectPinNumber),
ClockFrequency = 4000000,
Mode = SpiMode.Mode0,
ChipSelectType = SpiChipSelectType.Gpio,
ChipSelectHoldTime = TimeSpan.FromTicks(10),
ChipSelectSetupTime = TimeSpan.FromTicks(10)
};
netInterfaceSettings.SpiApiName = spiControllerName;
netInterfaceSettings.GpioApiName = SC20260.GpioPin.Id;
netInterfaceSettings.SpiSettings = settings;
netInterfaceSettings.InterruptPin = gpio.OpenPin(irqPinNumber);
netInterfaceSettings.InterruptEdge = GpioPinEdge.FallingEdge;
netInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;
netInterfaceSettings.ResetPin = gpio.OpenPin(resetPinNumber);
netInterfaceSettings.ResetActiveState = GpioPinValue.Low;
networkController.SetCommunicationInterfaceSettings(netInterfaceSettings);
}
}
}
FEZ.Bit-Code (working):
using System;
using System.Diagnostics;
using System.Net;
using System.Threading;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Network;
using GHIElectronics.TinyCLR.Devices.Spi;
using GHIElectronics.TinyCLR.Pins;
namespace FEZ.Bit_Wifi_Test
{
internal class Program
{
static string ssid = "mySSID";
static string pw = "myPw";
private static readonly NetworkController networkController = NetworkController.FromName
(SC20100.NetworkController.ATWinc15x0);
private static void Main()
{
// Wifi
InitWifiModule();
WiFiNetworkInterfaceSettings networkSettings = new WiFiNetworkInterfaceSettings
{
Ssid = ssid,
Password = pw,
DhcpEnable = true,
DynamicDnsEnable = true
};
networkController.SetInterfaceSettings(networkSettings);
networkController.SetAsDefaultController();
//Wait for IP address
var isReady = false;
networkController.NetworkAddressChanged += (a, b) =>
{
var ipProperties = a.GetIPProperties();
Debug.WriteLine("IP: " + ipProperties.Address);
var address = ipProperties.Address.GetAddressBytes();
if (address[0] != 0 && address[1] != 0)
isReady = true;
};
Debug.WriteLine("Enable the network controller.");
networkController.Enable();
Debug.WriteLine("Network controller is enabled.");
while (!isReady)
Thread.Sleep(100);
IPHostEntry ip = Dns.GetHostEntry("branscheid-gmbh.com");
Debug.WriteLine("BIA' IP = " + ip.AddressList[0].ToString());
Thread.Sleep(Timeout.Infinite);
}
private static void InitWifiModule()
{
//Setup Pins
var enablePinNumber = FEZBit.GpioPin.WiFiEnable;
var chipSelectPinNumber = FEZBit.GpioPin.WiFiChipselect;
var irqPinNumber = FEZBit.GpioPin.WiFiInterrupt;
var resetPinNumber = FEZBit.GpioPin.WiFiReset;
var spiControllerName = FEZBit.SpiBus.WiFi;
var gpio = GpioController.GetDefault();
var enablePin = gpio.OpenPin(enablePinNumber);
enablePin.SetDriveMode(GpioPinDriveMode.Output);
enablePin.Write(GpioPinValue.High);
SpiNetworkCommunicationInterfaceSettings netInterfaceSettings =
new SpiNetworkCommunicationInterfaceSettings();
var settings = new SpiConnectionSettings()
{
ChipSelectLine = gpio.OpenPin(chipSelectPinNumber),
ClockFrequency = 4000000,
Mode = SpiMode.Mode0,
ChipSelectType = SpiChipSelectType.Gpio,
ChipSelectHoldTime = TimeSpan.FromTicks(10),
ChipSelectSetupTime = TimeSpan.FromTicks(10)
};
netInterfaceSettings.SpiApiName = spiControllerName;
netInterfaceSettings.GpioApiName = SC20260.GpioPin.Id;
netInterfaceSettings.SpiSettings = settings;
netInterfaceSettings.InterruptPin = gpio.OpenPin(irqPinNumber);
netInterfaceSettings.InterruptEdge = GpioPinEdge.FallingEdge;
netInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp;
netInterfaceSettings.ResetPin = gpio.OpenPin(resetPinNumber);
netInterfaceSettings.ResetActiveState = GpioPinValue.Low;
networkController.SetCommunicationInterfaceSettings(netInterfaceSettings);
}
}
}