CAN .SetGroupFilters - Confused user.,

Hi,

I’m hoping someone can point me in the right direction.

Just working with the CAN bus and I have it working creating messages on one board and sending to another with no problems other than SetGroupFilters and SetExplicitFilters seem to be blocking everything out.

I am using the sample code from the helpfile other than I have changed this line:

msgList[0].ArbID = 0x55;

to

msgList[0].ArbID = 0x1234;

If I don’t set any filters I get the message as expected, but as soon as I uncomment the 3 lines:

 // Use channel 1
                    canPort = new CAN(CAN.Channel.Channel_1, (uint)(((T2 - 1) << 20) | ((T1 - 1) << 16) | ((BRP - 1) << 0)));

                    //Comment these out and it works, uncomment and it doesn't...
                    uint[] lowerBounds = new uint[] { 0x1000 };
                    uint[] upperBounds = new uint[] { 0x2000 };
                    canPort.SetGroupFilters(lowerBounds, upperBounds);
                    //********************************************************

                    // Subscribe to events
                    canPort.DataReceivedEvent += new CANDataReceivedEventHandler(can_DataReceivedEvent);
                    canPort.ErrorReceivedEvent += new CANErrorReceivedEventHandler(can_ErrorReceivedEvent);

then it refuses to fire the DataReceivedEvent…

Where am I going wrong.

Thanks in advance,

Andy

so you set the group filter to be 0x1000 to 0x2000 and sending a message from another node to 0x1234 but the message is not received?

Which device?

Sorry, should have said: Usbizi100

//A

@ Thor69UK

I ran this code and I am able to send and receive messages withing the bounds of the filter.

Here is the code I am using:


using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

namespace PandaCAN
{
    public class Program
    {
        static CAN.Message[] msgList;

        public static void Main()
        {
            Utility.SetLocalTime(new DateTime(2011, 2, 14, 0, 0, 0));

            int T1, T2, BRP;

            BRP = 24;
            T1 = 15;
            T2 = 8;

            // Create a message list of 100 messages
            msgList = new CAN.Message[100];
            for (int i = 0; i < msgList.Length; i++)
                msgList[i] = new CAN.Message();

            // Use channel 1
            CAN can = new CAN(CAN.Channel.Channel_1, (uint)(((T2 - 1) << 20) | ((T1 - 1) << 16) | ((BRP - 1) << 0)));

            //Comment these out and it works, uncomment and it doesn't...
            uint[] lowerBounds = new uint[] { 0x1000 };
            uint[] upperBounds = new uint[] { 0x2000 };
            can.SetGroupFilters(lowerBounds, upperBounds);

            // Subscribe to events
            can.DataReceivedEvent += new CANDataReceivedEventHandler(can_DataReceivedEvent);
            can.ErrorReceivedEvent += new CANErrorReceivedEventHandler(can_ErrorReceivedEvent);

            // Example for sending one message

            // msg ID
            msgList[0].ArbID = 0x1234;

            // Send the 8 bytes for example
            msgList[0].Data[0] = 1;
            msgList[0].Data[1] = 2;
            msgList[0].Data[2] = 3;
            msgList[0].Data[3] = 4;
            msgList[0].Data[4] = 5;
            msgList[0].Data[5] = 6;
            msgList[0].Data[6] = 7;
            msgList[0].Data[7] = 8;

            msgList[0].DLC = 8;
            msgList[0].IsEID = false;
            msgList[0].IsRTR = false;

            // Send one message
            int numberOfMessagesPosted = can.PostMessages(msgList, 0, 1);

            // Sleep forever
            Thread.Sleep(Timeout.Infinite);
        }

        static void can_DataReceivedEvent(CAN sender, CANDataReceivedEventArgs args)
        {
            Debug.Print(">>> can_DataReceivedEvent <<<");

            // read as many messages as possible
            int count = sender.GetMessages(msgList, 0, msgList.Length);
            for (int i = 0; i < count; i++)
            {
                Debug.Print("MSG: ID = " + msgList[i].ArbID + " at time = " + msgList[i].TimeStamp);
            }
        }

        static void can_ErrorReceivedEvent(CAN sender, CANErrorReceivedEventArgs args)
        {
            Debug.Print(">>> can_ErrorReceivedEvent <<<");

            switch (args.Error)
            {
                case CAN.Error.Overrun:
                    Debug.Print("Overrun error. Message lost");
                    break;

                case CAN.Error.RXOver:
                    Debug.Print("RXOver error. Internal buffer is full. Message lost");
                    break;

                case CAN.Error.BusOff:
                    Debug.Print("BusOff error. Reset CAN controller.");
                    sender.Reset();
                    break;
            }
        }
    }
}

How do you have CAN set up on Panda II?

Hi,

Thanks for your mail. I don’t have this setup on a Panda I have it on a USBizi100 chip on a custom set of boards.

I did find the problem if it helps anyone else:

It’s all down to this line:

msgList[0].IsEID = false; 

Looking at the first 11 bits of 0x1000 in binary are all 0’s and the first 11 bits of 0x2000 is also all the 0’s. So my filter is set up to not allow anything unless it is address 0x0!

Hope this helps someone. Had me scratching my head for a while…

:slight_smile:

//A

The difference between the basic and extended frame format is the B identifier, Google is your friend to get more info on this :wink: