I have been trying to get the can working between a Panda II and a Mini using the 82c250 transceiver chips.
I cannot get the can to work using the below code. I am not seeing any erorrs, the PostedMessagesSent is always false. Additionally on the scope it does not look like there is any activity on the Can Out lines (a 20Mhz scope should be fast enough??).
I would like to know why PostedMessagesSent is always false, is this a hardware or software issue.
using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
namespace CanTestPanda
{
public class Program
{
static CAN.Message[] msgList;
static CAN.Message[] msgListSend;
static CAN can;
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;
BRP = 24;
T1 = 15;
T2 = 8;
// Use channel 1
can = new CAN(CAN.Channel.Channel_1, (uint)(((T2 - 1) << 20) | ((T1 - 1) << 16) | ((BRP - 1) << 0)));
can.Reset();
// 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();
can.DisableExplicitFilters();
can.DisableGroupFilters();
// subscribe to events
can.DataReceivedEvent += new CANDataReceivedEventHandler(can_DataReceivedEvent);
can.ErrorReceivedEvent += new CANErrorReceivedEventHandler(can_ErrorReceivedEvent);
msgListSend = new CAN.Message[1];
msgListSend[0] = new CAN.Message();
while (true)
{
msgListSend[0].ArbID = 0x55;
// set a timestamp
long adcMessageStartTicks = DateTime.Now.Ticks;
msgListSend[0].Data[0] = (byte)(adcMessageStartTicks & 0xFF);
msgListSend[0].Data[1] = (byte)((adcMessageStartTicks >> 8) & 0xFF);
msgListSend[0].Data[2] = (byte)((adcMessageStartTicks >> 16) & 0xFF);
msgListSend[0].Data[3] = (byte)((adcMessageStartTicks >> 24) & 0xFF);
msgListSend[0].Data[4] = (byte)((adcMessageStartTicks >> 32) & 0xFF);
msgListSend[0].Data[5] = (byte)((adcMessageStartTicks >> 40) & 0xFF);
msgListSend[0].Data[6] = (byte)((adcMessageStartTicks >> 48) & 0xFF);
msgListSend[0].Data[7] = (byte)((adcMessageStartTicks >> 56) & 0xFF);
// Send the 8 bytes for example
msgList[0].DLC = 8;
msgList[0].IsEID = false;
msgList[0].IsRTR = false;
can.PostMessages(msgListSend, 0, 1);
if (can.TransmitErrorCount > 0)
{
Debug.Print("Error COunt = " + can.TransmitErrorCount);
}
Thread.Sleep(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;
}
}
}
}