Main Site Documentation

CAN SENT problem


#1

I only have a board FEZPanda_II and I use the code on the www.tingyclr.com to debug. But CAN1 TXD can not send any message out. The debug window always display “BusOff error. Reset CAN controller”.

Must I have two nodes so that it can run successfully?

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()
{
           Utility.SetLocalTime(new DateTime(2011, 2, 14, 0, 0, 0));

    int T1, T2, BRP;

    
    
    BRP = 24;
    T1 = 15;
    T2 = 8;
    CAN can = new CAN(CAN.Channel.Channel_1, (uint)(((T2 - 1) << 20) | ((T1 - 1) << 16) | ((BRP - 1) << 0)));
    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;
    }
}

}


#2

Go here http://tinyclr.com/support/ and take a look at CAN tutorial please.

You need PHY and termination or CAN will not work.


#3

Gus,

On another note: The video for “RLP Video Playback” tutorial doesn’t work. Tells me that the video isn’t available anymore because the user that uploaded it has closed their account…


#4

Errorl, You meant to reply to RLP question? Or this is a bug in forum. How did your question end up here?


#5

Sorry. That is why the “On another note”.

You directed this user to the tutorials. Then I browsed the tutorials, and saw the broken video… :frowning:

Sorry about the confusion…


#6

Funny, someone was talking about it in another thread and I thought you were replying. We lost this RLP video while we were moving our youtube account.


#7

;D
;D

Haha, smiley doesn’t work as first chars… :slight_smile: