G120 custom board CAN Request is not responding

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.

I think the CAN object has an enabled property, which must be set to true.
Also the baud rate must not be set directly, but calculated somehow, if I remember right.
The CAN chip we use also needs a Hardware pin set to be able to receive something.

What I also find strange:
You use NETMF 4.3, but GHI has changed the CAN class Name to ControllerAreaNetwork.
Why can you use CAN?
What is the full Name of the CAN class you are using?
Is this some Gadgeteer class?
If yes, try to use GHI.IO.ControllerAreaNetwork in GHI.Hardware assembly.
https://www.ghielectronics.com/downloads/man/Library_Documentation_v4.3/

I also don’t quite understand waht you mean by “Adaptor running custom-built firmware running at 250Khz”

I work with Bitoo on this project so we’re constructing this response together.

We are actually using 4.2 of the GHI runtime environment - sorry for the confusion. So we are using the calculation, as you suggest (please see code below). Does this look right to you?

// Databus recommendation: Bitrate = 250Kbps, SP% > 85%
// Processor clock = 72 mhz
// Baud Rate Prescaler (BRP) = 12
// Use BRP=3 for 1Mbps, BRP=6 for 500Kbps, BRP=12 for 250Kbps, and BRP=24 for 125Kpbs
// CAN Clock = Processor Clock / BRP (72Mhz / 12 = 6Mhz CAN Clock)
// TQ = CAN Clock / Bitrate (6Mhz/250Kbps = 24 TQ)
// Bitrate values from calculator at http://www.kvaser.com/can/protocol/index.htm
// From calculator with TQ = 24, pick T1 = 16, T2 = 8

    // PTC recommends the following:
    // Pick best values from calculator (T1 = 14, T2 = 2, TQ = 16)
    // BRP = Processor Clock / Bitrate / TQ (72Mhz / 250Kbps / 16) = 18

    // T1 = 14
    // T2 = 2
    // TQ = 16
    // SP% = 87.5 (meets our spec)
    // BRP = 18
    // Sync bit = 1
    // Sync bit needs to be included so it is considered part of T1 (see BTR equation)
    // Bus Timing Register (BTR) = ((T2 - 1) << 20) | (((T1 - Sync) - 1) << 16) | ((BRP - 1) << 0)

By “adaptor” we are referring to a Deutsch connector that expects baud rates of 250 Khz. The adaptor is wired to our circuit board and then plugs into a vehicle.

We are using the CAN Transceiver SN65HVD230DR by Texas Instruments. We looked at the schematic for our board and it looks like all the right traces are going from the transceiver to and from G120. The one that I’m not sure about is PIN 8 on the transceiver which is currently pulled to Ground. Here are the comments made in the technical doc for the transceiver:

R SN65HVD230 and SN65HVD231: Mode select pin: strong pull down to GND = high speed mode, strong S 8 I pull up to VCC = low power mode, 10kΩ to 100kΩ pull down to GND = slope control mode
NC I SN65HVD232: No Connect

In addition the documentation provides these comments…

10.4.3 Standby Mode (Listen Only Mode) of the HVD230
If a logic high (> 0.75 VCC) is applied to RS (pin 8) in Figure 30 and Figure 32, the circuit of the SN65HVD230
enters a low-current, listen only standby mode, during which the driver is switched off and the receiver remains
active. In this listen only state, the transceiver is completely passive to the bus. It makes no difference if a slope
control resistor is in place as shown in Figure 32. The μP can reverse this low-power standby mode when the
rising edge of a dominant state (bus differential voltage > 900 mV typical) occurs on the bus. The μP, sensing
bus activity, reactivates the driver circuit by placing a logic low (< 1.2 V) on RS (pin 8).

Thank in advance for any insight you can provide.

@ michellemoline - If you want to try to narrow the issue down some, try talking between two G120 boards over CAN and not any external hardware. If the G120 boards can talk to each other fine, then it is possible that the bitrate is not quite right for talking to the external board.