We are using a custom built board that has the G120 to communicate to the CAN bus of heavy-duty vehicles. The toolchain consists of:
• Microsoft Visual Studio Express 2012
• Microsoft .NET Micro Framework (NETMF) 4.3
• GHI NETMF and Gadgeteer Package 2014 R2
• Adaptor running custom-built firmware running at 250Khz
• CAN simulator
We are not getting back any data from the CAN bus. We know that the CAN simulator is working well and that we are sending valid CAN request messages to the adaptor. We don’t think it’s a hardware issue, but just in case have attached a picture of the schematic involving the CAN.
I am attaching a sample code which is I tried only to check working of the CAN -
/* ========SAMPLE CODE ========*/
private const Byte T1 = 16;
private const Byte T2 = 8;
private const Byte BRP = 10;
private const Byte Sync = 1;
private const Int32 BTR = ((T2 - 1) << 20) | (((T1 - Sync) - 1) << 16) | ((BRP - 1) << 0);
public static void Main()
{
//init can fixed parameters
can1 = new CAN(CAN.Channel.Channel_1, BTR, 100);
can1.DataReceivedEvent += can1_DataReceivedEvent;
can1.ErrorReceivedEvent += can1_ErrorReceivedEvent;
//fixed dummy message
msgOut = new CAN.Message[1];
msgOut[0] = new CAN.Message();
msgOut[0].IsEID = true;
msgOut[0].ArbID = 0x18FEE6EE;
msgOut[0].Data[0] = 255;
msgOut[0].DLC = 1;
//highest prio thread sending can messages out
SendCanMsg1 = new Thread(SendCanMsg1Thread);
SendCanMsg1.Priority = ThreadPriority.Highest;
SendCanMsg1.Start();
Debug.Print("CAN started");
//sleep for 1 second (to log some can messages first)
Thread.Sleep(1000);
}
static void SendCanMsg1Thread()
{
while (true)
{
int _ret = can1.PostMessages(msgOut, 0, 1);
Debug.Print("Can postmessage count=" + _ret.ToString() + " on " + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString() + ":" + DateTime.Now.Millisecond.ToString());
Thread.Sleep(100);
}
}
static void can1_ErrorReceivedEvent(CAN sender, CANErrorReceivedEventArgs args)
{
Debug.Print("Can error = " + args.Error.ToString());
}
static void can1_DataReceivedEvent(CAN sender, CANDataReceivedEventArgs args)
{
Debug.Print("Can message received = "+ args.ToString());
}
/==============END=========================/
OUTPUTS
Can postmessage count=1 on 28:13:654
CAN started
Can postmessage count=0 on 28:13:958
Can postmessage count=0 on 28:14:263
Can postmessage count=0 on 28:14:567
Can postmessage count=0 on 28:14:871
Can postmessage count=0 on 28:15:176
Can postmessage count=0 on 28:15:481
Can postmessage count=0 on 28:15:785
Can postmessage count=0 on 28:16:89
Can postmessage count=0 on 28:16:393
Can postmessage count=0 on 28:16:698
Can postmessage count=0 on 28:17:2
Can postmessage count=0 on 28:17:306
Can postmessage count=0 on 28:17:610
Can postmessage count=0 on 28:17:914
Can postmessage count=0 on 28:18:218
Can postmessage count=0 on 28:18:523
The thread ‘’ (0x1) has exited with code 0 (0x0).
Can postmessage count=0 on 28:18:827
Can postmessage count=0 on 28:19:131
I was expecting a CAN response for the above example, even if an error.
Please share your comment if my sample code is correct to prove that the CAN is not responding. I am looking forward to have your guidance to identify the error.