Hello,
I tried to start with CAN on the G400 module. I made my own board with LCD display and with 2 CAN drivers. I tried to made an example code from GHI web sites for introduction and communication between G400 and Kvaser USB/CAN.
I didn’t have a problem with first deploying, but the program didn’t work and G400 has a text “ABORT data” on LCD display. The worst is I can’t to update my G400 module using FEZConfig software. I tried to make it again with the other G400 module and I have 2 dead modules.
Thank you for the answers.
My code is:
static CAN.Message[] TxMessages;
static CAN.Message[] RxMessages;
public static bool Error = false;
public static void Main()
{
int T1, T2, BRP;
//Bitrate 250 kbit/s
BRP = 24;
T1 = 15;
T2 = 8;
TxMessages = new CAN.Message[1];
RxMessages = new CAN.Message[1];
for (int i = 0; i < TxMessages.Length; i++)
{
TxMessages[i] = new CAN.Message();
}
CAN AntriebCAN = new CAN(CAN.Channel.Channel_1, (uint)(((T2 - 1) << 20) | ((T1 - 1) << 16) | ((BRP - 1) << 0)));
AntriebCAN.DataReceivedEvent += AntriebCAN_DataReceivedEvent;
AntriebCAN.ErrorReceivedEvent += AntriebCAN_ErrorReceivedEvent;
TxMessages[0].ArbID = 100;
TxMessages[0].Data[0] = 1;
TxMessages[0].DLC = 1;
TxMessages[0].IsEID = false;
TxMessages[0].IsRTR = false;
while (true)
{
if (Error == false)
AntriebCAN.PostMessages(TxMessages, 0, 1);
else
Error = false;
Thread.Sleep(1000);
}
Debug.Print("Sleeping...");
Thread.Sleep(Timeout.Infinite);
}
static void AntriebCAN_DataReceivedEvent(CAN sender, CANDataReceivedEventArgs args)
{
Debug.Print("Data received event");
int count = sender.GetMessages(RxMessages, 0, 1);
Debug.Print("MSG: ID = " + RxMessages[0].ArbID + " at time " + RxMessages[0].TimeStamp);
}
static void AntriebCAN_ErrorReceivedEvent(CAN sender, CANErrorReceivedEventArgs args)
{
Debug.Print("Error received");
Error = true;
switch (args.Error)
{
case CAN.Error.Overrun:
Debug.Print("Overrun error");
break;
case CAN.Error.RXOver:
Debug.Print("RXOver error");
break;
case CAN.Error.ErrorPassive:
Debug.Print("Error Passive");
break;
}
}