I had some issues on my ported code from NETMF and create a basic test program where i set these:
//my test filter
can1.Filter.AddMaskFilter(Filter.IdType.Extended, 0x12000000, 0xFFFFFFFF);
//from tutorial:
can1.Filter.AddRangeFilter(Filter.IdType.Standard, 0x12, 0x20);
can1.Filter.AddMaskFilter(Filter.IdType.Standard, 0x11, 0xFD);
I put external on the bus
0x11 → received (ok)
0x12 → received (ok)
0x25 → nothing (ok)
0x11000000 → nothing (ok)
0x12000000 → received (ok) this is the filter
0x12500000 → recieved (not ok)
0x13000000 → received (not ok)
Any ID higher then the ID in the extended filter seems to pass.
This is done on SC20260 running TinyClr 2.1.0.6500 (extende heap and deployment activated)
Debug output:
Test app:
using GHIElectronics.TinyCLR.Devices.Can;
using GHIElectronics.TinyCLR.Pins;
using System.Diagnostics;
using System.Threading;
namespace Test_CAN_sample_code
{
public class Startup
{
public static CanController can1;
public static CanMessage[] canMessage1;
static void Main()
{
can1 = CanController.FromName(SC20260.CanBus.Can1);
can1.SetNominalBitTiming(new CanBitTiming(13, 2, 24, 1, false));
canMessage1 = new CanMessage[1];
canMessage1[0] = new CanMessage();
canMessage1[0].Length = 8;
canMessage1[0].Data = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x2E, 0x20, 0x20 };
canMessage1[0].ArbitrationId = 285212672; //0x11000000
canMessage1[0].RemoteTransmissionRequest = false;
canMessage1[0].ExtendedId = true;
canMessage1[0].FdCan = false;
canMessage1[0].BitRateSwitch = false;
can1.MessageReceived += Can1_MessageReceived;
can1.ErrorReceived += Can1_ErrorReceived;
//my test filter
can1.Filter.AddMaskFilter(Filter.IdType.Extended, 0x12000000, 0xFFFFFFFF);
//from tutorial:
can1.Filter.AddRangeFilter(Filter.IdType.Standard, 0x12, 0x20);
can1.Filter.AddMaskFilter(Filter.IdType.Standard, 0x11, 0xFD);
can1.Enable();
while (true)
{
if (can1.CanWriteMessage)
{
can1.WriteMessage(canMessage1[0]);
Debug.WriteLine("can 1 write " + canMessage1[0].ArbitrationId.ToString("X8"));
}
else
{
Debug.WriteLine("can 1 write failed");
}
Thread.Sleep(500);
}
}
public static void Can1_MessageReceived(CanController sender, MessageReceivedEventArgs e)
{
sender.ReadMessage(out var message);
Debug.WriteLine("Received Arbitration ID: 0x" + message.ArbitrationId.ToString("X8"));
}
public static void Can1_ErrorReceived(CanController sender, GHIElectronics.TinyCLR.Devices.Can.ErrorReceivedEventArgs e)
{
Debug.WriteLine("CAN1 error " + e.ToString());
}
}
}