CAN.GetRxQueueCount Not Working in MF V4 on FEZ Cobra

I converted my CAN project from EMX Dev MF V3.0 to FEZ Cobra MF V4.1 and it doesn’t quite work correctly. Here is the issue I’m having.

The CAN.GetRxQueueCount is initially populated with a count of 126. I call CAN.GetMessages 126 times and retrieve the data. Once the count reaches 0, it stays 0 and I don’t get anymore data. The exact same code works fine in MF V3 on my EMX Dev board.

Here is the V4.1 code:

    CAN.Message[] GHIMessages = new CAN.Message[1];
    GHIMessages[0] = new CAN.Message();

    while (true)
    {
        if (CanBus.GetRxQueueCount() != 0)
        {
            CanBus.GetMessages(GHIMessages);
            foreach (CAN.Message GHIMessage in GHIMessages)
            {
                // Process the message
            }
        }
    }

Are you using the latest SDK online?
There are several projects done on V4 that use CAN so it should work fine.
Start with a simple CAN test to make sure the problem is not coming from somewhere else.

SDK is 4.1.3 (the file version on the dll) which I believe is the most current, correct?

I’ve narrowed it down to the the PostMessages method. It seems that when I call PostMessages, I no longer receiving any in-coming messages. GetMessages works fine until the call to PostMessages, then GetRxQueueCount goes to 0 and stays there.

I have searched in vain for other projects but have not found any. If you know of any, please send me a link.

Could this be in any way related to hardware. My hardware guy did have to solder a small chip to convert CAN R/T to CAN High/Low.

A possibility that your bit timeing is off do when you fail to send, the controller goes “bus off” condition

The bit timing is the same as what I’m using with the EMX dev board and V3 which works fine. Here is the code I’m using for both the EMX dev board/V3 and the FEZ Cobra/V4:

        // Truck databus recommendation: Bitrate = 250Kbps, SP% > 85%
        // Processor clock = 72 mhz
        // Baud Rate Prescaler (BRP) = 12
        // Use BRP=3 for 1Mbps, BRP=6 for 500Kbps, BRP=12 for 250Kbps, and BRP=24 for 125Kpbs
        // CAN Clock = Processor Clock / BRP (72Mhz / 12 = 6Mhz CAN Clock)
        // TQ = CAN Clock / Bitrate (6Mhz/250Kbps = 24 TQ)
        // Bitrate values from calculator at http://www.kvaser.com/can/protocol/index.htm
        // From calculator with TQ = 24, pick T1 = 16, T2 = 8

        // PTC recommends the following:
        // Pick best values from calculator (T1 = 14, T2 = 2, TQ = 16)
        // BRP = Processor Clock / Bitrate / TQ (72Mhz / 250Kbps / 16) = 18

        // T1 = 14
        // T2 = 2
        // TQ = 16
        // SP% = 87.5 (meets our spec)
        // BRP = 18
        // Sync bit = 1
        // Sync bit needs to be included so it is considered part of T1 (see BTR equation)
        // Bus Timing Register (BTR) = ((T2 - 1) << 20) | (((T1 - Sync) - 1) << 16) | ((BRP - 1) << 0)

        const Byte T1 = 14;
        const Byte T2 = 2;
        const Byte BRP = 18; // Truck
        const Byte Sync = 1;
        const Int32 BTR = ((T2 - 1) << 20) | (((T1 - Sync) - 1) << 16) | ((BRP - 1) << 0);

        CanBus = new CAN(CAN.Channel.Channel_1, BTR);

Do you have or can you provide documentation for wiring up a CAN tranceiver? I was looking at my old GHI dev boards trying to figure out if you ground the TI VP230 tranceiver’s Pin-8 to cause high speed operation, and also how you wired in the terminating resistor. I’m thinking it might be the transceiver wiring that is causing my inability to send CAN messages.

Please start new thread for new topics so we can help you better.

You can use the EMX DevSys schematics to see how the transceiver is wired.

Got it and when I grounded Pin-8 everything started working. I sent the schematic to my hardware guy and he’s going to add the other resistors, etc. Thanks for the help.