CAN Issues

Hello all,

I am attempting to run a CAN bus between two Fez Panda II modules. I have used the MCP 2551 CAN Transceiver chip as spec’d out in the data sheet. I am connected to CAN1 on both boards and i am using the code from the tutorials. i have two computers monitoring both FEZ units. When i start the both units i get an error Busoff. I have used an oscilloscope and can see the original message go across the bus.

I have also noticed that the Busoff error occurs only once if the other FEZ is not running the code. when it starts the first unit has the Busoff error continuously.

The bus has 120ohm resistors at each end as terminators and the bus length is 36"

Any ideas?

the code -

 
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
 
public class Program
{
    // Messages list
    static CAN.Message[] msgList;
 
    public static void Main()
    {
        // Set the system time. CAN messages will have a time stamp
        Utility.SetLocalTime(new DateTime(2011, 2, 14, 0, 0, 0));
 
        int T1, T2, BRP;
 
        // These numbers were calculated using the calculator on this link:
        // http://www.kvaser.com/can/protocol/index.htm
        // We used the very first value from the calculator output
 
        /////////////////////////////////////////////////////////////////////////////////////////////
        // Bitrate 250Kbps
        // CLK = 72 Mhz, with BRP = 12 -> 6Mhz CAN clock
        // 6Mhz/250Kbps = 24 TQ
        // T1 = 16 minus 1 for sync = 15
        // T2 = 8
        // 15 + 1 + 8 = 24 TQs which is what we need
        /////////////////////////////////////////////////////////////////////////////////////////////
        // uncomment to use this bit timing
        //BRP = 12;
        //T1 = 15;
        //T2 = 8;
 
        /////////////////////////////////////////////////////////////////////////////////////////////
        // Bitrate 125Kbps
        // CLK = 72 Mhz, with BRP = 24 -> 3Mhz CAN clock
        // 3Mhz/125Kbps = 24 TQ
        // T1 = 16 minus 1 for sync = 15
        // T2 = 8
        // 15 + 1 + 8 = 24 TQs which is what we need
        /////////////////////////////////////////////////////////////////////////////////////////////
        // uncomment to use this bit timing
        BRP = 24;
        T1 = 15;
        T2 = 8;
 
        // For 500Kbps you can use BRP=6 and for 1Mbps you can use BRP=3 ...and so on
 
        // Use channel 1
        CAN can = new CAN(CAN.Channel.Channel_1, (uint)(((T2 - 1) << 20) | ((T1 - 1) << 16) | ((BRP - 1) << 0)));
 
        // 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();
 
        /*
        // example for sending one message
        // msg ID
        msgList[0].ArbID = 0x55;
        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;
        // Send the 8 bytes for example
        msgList[0].DLC = 8;
        msgList[0].IsEID = false;
        msgList[0].IsRTR = false;
        // Send one messages
        int numberOfMessagesPosted = can.PostMessages(msgList, 0, 1);
        */
 
        // subscribe to events
        can.DataReceivedEvent += new CANDataReceivedEventHandler(can_DataReceivedEvent);
        can.ErrorReceivedEvent += new CANErrorReceivedEventHandler(can_ErrorReceivedEvent);
 
        // 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;
        }
    }
}

Funny, we are actually running few tests on CAN as we speak. CAN should be working fine but we will be providing some more details to make this easier for everyone. Stay tuned please.

Thanks Gus,

Its been getting a little frustrating. Anything that helps diagnose the issues would be great.

Cheers
Jason