I noticed some unwanted behavior on my custom G120 board…
CAN communication stops for 3 seconds when the WIFI switched on.
Is this normal behavior or could this be a problem in the design?
I have some basic test code bellow that gives me a 100% reproduction.
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Net.Sockets;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Net;
using Microsoft.SPOT.Time;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Media;
using GHI.Premium.IO;
using GHI.Premium.Net;
using GHI.Hardware.G120;
using GHI.Premium.System;
using GHI.Premium.USBHost;
using GHI.Premium.Hardware;
using GHI.Premium.USBClient;
using GHI.Premium.Hardware.LowLevel;
namespace WifiHickup
{
public class Program
{
static CAN can1;
static CAN.Message[] msgOut;
static Thread SendCanMsg1;
static WiFiRS9110 Wifi;
static Thread StartWifi;
public static void Main()
{
//init wifi module
Wifi = new WiFiRS9110(SPI.SPI_module.SPI2, GHI.Hardware.G120.Pin.P1_27, GHI.Hardware.G120.Pin.P2_13, GHI.Hardware.G120.Pin.P1_28, 4000);
Wifi.NetworkAddressChanged += Wifi_NetworkAddressChanged;
Wifi.WirelessConnectivityChanged += Wifi_WirelessConnectivityChanged;
//init can fixed parameters
can1 = new CAN(CAN.Channel.Channel_1, (uint)(((8 - 1) << 20) | ((15 - 1) << 16) | (0 << 14) | ((20 - 1) << 0)), 100);
can1.DataReceivedEvent += can1_DataReceivedEvent;
can1.ErrorReceivedEvent += can1_ErrorReceivedEvent;
//Just pusch 0xFFFFFFFF in filter in to keep buffers empty
uint[] explicitIDs = new uint[] { 4294967295 };
can1.SetExplicitFilters(explicitIDs);
//fixed dummy message
msgOut = new CAN.Message[1];
msgOut[0] = new CAN.Message();
msgOut[0].IsEID = true;
msgOut[0].ArbID = 0x18FEE6EE;
msgOut[0].Data[0] = 255;
msgOut[0].Data[1] = 255;
msgOut[0].Data[2] = 255;
msgOut[0].Data[3] = 255;
msgOut[0].Data[4] = 255;
msgOut[0].Data[5] = 255;
msgOut[0].Data[6] = 255;
msgOut[0].Data[7] = 255;
//highest prio thread sending can messages out
SendCanMsg1 = new Thread(SendCanMsg1Thread);
SendCanMsg1.Priority = ThreadPriority.Highest;
//lowest prio thread opening wifi
StartWifi = new Thread(StartWifiThread);
StartWifi.Priority = ThreadPriority.Lowest;
SendCanMsg1.Start();
Debug.Print("CAN started");
//sleep for 1 second (to log some can messages first)
Thread.Sleep(1000);
//start thread opening wifi
StartWifi.Start();
Debug.Print("WIFI started");
Thread.Sleep(Timeout.Infinite);
Debug.Print("FINITO...");
}
static void StartWifiThread()
{
if (Wifi.IsOpen == false)
{
Wifi.Open();
}
//only when it's actualy open !!!
if (Wifi.IsOpen == true)
{
if (!Wifi.NetworkInterface.IsDhcpEnabled)
{
//i always use DHCP on WIFI
Wifi.NetworkInterface.EnableDhcp();
}
// assign networkstack
NetworkInterfaceExtension.AssignNetworkingStackTo(Wifi);
WiFiNetworkInfo[] WifiScanResult = Wifi.Scan();
for (int i = 0; i < WifiScanResult.Length; i++)
{
if (WifiScanResult[i].SSID == "WLANEmrol2")
{
Wifi.Join(WifiScanResult[i], "********");
break;
}
}
}
}
static void Wifi_WirelessConnectivityChanged(object sender, WiFiRS9110.WirelessConnectivityEventArgs e)
{
Debug.Print("Wifi_WirelessConnectivityChanged");
}
static void Wifi_NetworkAddressChanged(object sender, EventArgs e)
{
Debug.Print("Wifi NetworkAddressChanged to " + Wifi.NetworkInterface.IPAddress.ToString());
}
static void SendCanMsg1Thread()
{
while (true)
{
//send the same msg every 100ms
int _ret = can1.PostMessages (msgOut,0,1);
Debug.Print("Can postmessage count=" + _ret.ToString() + " on " + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString());
Thread.Sleep(100);
}
}
static void can1_ErrorReceivedEvent(CAN sender, CANErrorReceivedEventArgs args)
{
Debug.Print("Can error");
}
static void can1_DataReceivedEvent(CAN sender, CANDataReceivedEventArgs args)
{
Debug.Print("Can message received");
}
}
}
Anny hints, tips our thoughts are much appreciated.
[EDIT] the screenshot shows the debug output where this hapens.
There is always a 3 sec silence somwere between driver version number and address changed.
I have played a little moree and it’s not CAN related, if i comment out sending the CAN message and just write the time to debug from this thread i have the same “hickup” :think:
Can postmessage count=0 on 14:33:561
Can postmessage count=0 on 14:33:665
------------------- a gap from 3.5 seconds----------------
Can postmessage count=0 on 14:37:197
Can postmessage count=0 on 14:37:301
Can postmessage count=0 on 14:37:406
Are there other users with the RS21 module who have this problem?
I’m going to create a test with the G120 HDR and the RS21 and another test with the raptor and the RS21 but is there anyone who could load the sample project without the CAN (just comment this out but leave the debug statement) on a FEZ cobra II to see if it’s design or default behavior?
At this point i have a complete lockup in the netmf console project for 3.5 seconds while WIFI is connecting and gets a IP address.
The code in the first message is a 100% reproduction for me, you can remove the actual sending off the can message and just send the time in the debug line to see the hickup.
At this point i try to find out if this is a hardware design error (we use IO’s that are initial used in the LCD and we did need to add some resistors (pull) to get this working during startup)
I did a setup today with a G120HDR and the raptor but seems my gadgeteer RS21 module
is broken, i always get some errors and a RS9110 firmware update call just hangs.
I will order some new ones tomorrow and also a couple FEZ Cobra II with wifi to compare and maybe create a breadboard version of the RS21 with a production RS9110 module.
A cleaned up version of the test code and the behavior:
debug window:
SendMsg thread started
Postmessage on 10:5:352
Postmessage on 10:5:458
*** deleted some lines over here ***
Postmessage on 10:6:188
Postmessage on 10:7:821
WIFI started
Postmessage on 10:7:926
Postmessage on 10:8:32
RS9110 firmware version Number is 4.4.5
RS9110 driver version Number is 4.4.5
Postmessage on 10:8:136
Postmessage on 10:8:241
*** deleted some lines over here ***
Postmessage on 10:12:100
Postmessage on 10:12:204 <<<<----------------- Highest prio thread completly stops
Postmessage on 10:15:738 <<<<----------------- for 3.5 seconds and then continues
Postmessage on 10:15:843
*** deleted some lines over here ***
Postmessage on 10:17:979
Postmessage on 10:18:83
Postmessage on 10:18:189
Wifi_WirelessConnectivityChanged
Wifi NetworkAddressChanged to 192.168.1.114
Postmessage on 10:19:562
Postmessage on 10:19:667
Postmessage on 10:19:772
Postmessage on 10:19:876
Postmessage on 10:19:981
Maybe i need to put this in a new topic because the subject is refering to CAN and CAN is not involved?
using System;
using Microsoft.SPOT;
using GHI.Premium.Net;
using System.Threading;
using GHI.Hardware.G120;
using Microsoft.SPOT.Hardware;
namespace WifiHickup
{
public class Program
{
static Thread SendMsg;
static Thread StartWifi;
static WiFiRS9110 Wifi;
public static void Main()
{
//Cobra II Wifi
Wifi = new WiFiRS9110(SPI.SPI_module.SPI2, Pin.P1_10,Pin.P2_11, Pin.P1_9, 4000);
Wifi.NetworkAddressChanged += Wifi_NetworkAddressChanged;
Wifi.WirelessConnectivityChanged += Wifi_WirelessConnectivityChanged;
//highest prio thread sending messages out
SendMsg = new Thread(SendMsgThread);
SendMsg.Priority = ThreadPriority.Highest;
//lowest prio thread opening wifi
StartWifi = new Thread(StartWifiThread);
StartWifi.Priority = ThreadPriority.Lowest;
SendMsg.Start();
Debug.Print("SendMsg thread started");
//sleep for 1 second (to log some messages first)
Thread.Sleep(1000);
//start thread opening wifi
StartWifi.Start();
Debug.Print("WIFI started");
Thread.Sleep(Timeout.Infinite);
Debug.Print("FINITO...");
}
static void StartWifiThread()
{
if (Wifi.IsOpen == false)
{
Wifi.Open();
}
//only when it's actualy open !!!
if (Wifi.IsOpen == true)
{
if (!Wifi.NetworkInterface.IsDhcpEnabled)
{
Wifi.NetworkInterface.EnableDhcp();
}
NetworkInterfaceExtension.AssignNetworkingStackTo(Wifi);
WiFiNetworkInfo[] WifiScanResult = Wifi.Scan();
for (int i = 0; i < WifiScanResult.Length; i++)
{
if (WifiScanResult[i].SSID == "WLANEmrol2")
{
Wifi.Join(WifiScanResult[i], "**********");
break;
}
}
}
}
static void Wifi_WirelessConnectivityChanged(object sender, WiFiRS9110.WirelessConnectivityEventArgs e)
{
Debug.Print("Wifi_WirelessConnectivityChanged");
}
static void Wifi_NetworkAddressChanged(object sender, EventArgs e)
{
Debug.Print("Wifi NetworkAddressChanged to " + Wifi.NetworkInterface.IPAddress.ToString());
}
static void SendMsgThread()
{
while (true)
{
//send the same msg every 100ms
Debug.Print("Postmessage on " + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString());
Thread.Sleep(100);
}
}
}
}
This is in a AGV (Automated guided vehicle) project where communication has a time out from 1000ms maximum. Wi-Fi is only available on some spots (the charging station for example) And if communication times out the vehicle shuts down and manual intervention is needed to get this started up again.
@ David@ Emrol - Sorry for the delay. We are able to reproduce the behavior on all of our devices. Until we address it, the only workaround I can really think of is to initialize WiFi before anything else if that delay causes problems.
@ John - Is there a (approx) time schedule on this?
We did the first setup in France this week to start testing and have about 2 months left before it’s going live with 50 AVG’s, by then i need a stable solution or workaround.
We could but we then we have to see how the behavior is when we move out of range of the access point and rescan or reconnect when we are back in range.