Cannot get can-bus to work on G120 demo board

What is the baud rate and sampling point settings for the CAN analyser?

Having the same baud rate but a different sampling point means that the devices won’t talk to each other. The sampling point is the critical bit.

I am just about to get started coding the G120 for CAN myself and this is the one part I will pay attention to.

@ zeroaviation -
you mean the four sticks to support it? I don’t know exactly, the length is about 2cm, I think the diameter you can find in the dimension of CAN_DW.

@ Dave McLaughlin -
The settings of CAN analyzer is as the picture shows.
The bitrate is defined here, but I am not sure baud rate is also defined according to bitrate.
And I don’t exactly understand the meaning of sampling point and Where can I set it in can analyzer. And do I need to set it in C# too?

Yes, I should have called it bitrate! Baud rate doesn’t really apply here.

Anyway, your bitrate must be the same and so must the sampling point. From what I can see, the sampling point for the samples on the G120 are set for 75%.

It the CAN analyser is set for 75% it should then work. If it is set for something else, it won’t work. For instance, CAN open spec uses 87.5% as the sampling point.

I am not familiar with the software but see if you can find anything to do with sampling point or time quanta etc.

@ Dave McLaughlin -
Thank you for your advice, but , ahhhhh, I don’t know where to find anything in the software about sampling point. Actually, I checked all buttons, but no sampling point.

If it is possible, could you give me some codes to test, which run well in your computer. Just very simple one is OK, like send or receive a complete can.message…

Thank you~~~

But in my personal opinion, it could not be the program problem, because, when even though I wrote a very simple one like follow, this data received event does not raise, when I transmit messages from Can analyzer to G120

can_dw2.InitializeCAN(15, 8, 20);

            can_dw2.DataReceived += new GTM.GHIElectronics.CAN_DW.DataReceivedEventHandler(can_dw2_DataReceived);
            can_dw2.ErrorReceived += new GTM.GHIElectronics.CAN_DW.ErrorReceivedEventHandler(can_dw2_ErrorReceived);
            can_dw2.PostDone += new GTM.GHIElectronics.CAN_DW.PostMessagesDoneEventHandler(can_dw2_PostDone);

            can_dw2.msgList = new GHI.Premium.Hardware.CAN.Message[15];

            for (int i = 0; i < can_dw2.msgList.Length; i++)
            {
                can_dw2.msgList[i] = new GHI.Premium.Hardware.CAN.Message();
                can_dw2.msgList[i].ArbID = 0x11;
                can_dw2.msgList[i].DLC = 0x01;
                can_dw2.msgList[i].Data[0] = (byte)i;
                can_dw2.msgList[i].IsEID = false;
                can_dw2.msgList[i].IsRTR = false;
                Debug.Print(can_dw2.msgList[i].ArbID.ToString() + can_dw2.msgList[i].DLC.ToString() + can_dw2.msgList[i].Data[0].ToString());
                Thread.Sleep(500);
                               
            }

            int numberOfMsgSent = 0;

            //Send all of the messages
            while (true)
            {
                // Post as many messages as possible.
                can_dw2.PostMessages(0, can_dw2.msgList.Length - numberOfMsgSent);

                // Record how many were sent.
                numberOfMsgSent += can_dw2.NumMessagesSent;

                // If we have sent all of the messgaes, break out of the loop.
                if (numberOfMsgSent == can_dw2.msgList.Length)
                    break;

                // Sleep to allow the messages time to transmit.
                System.Threading.Thread.Sleep(1);
            }
                      
        }

        void can_dw2_PostDone(int numPosted)
        {
            Debug.Print(numPosted.ToString() + " messages were posted");
            
        }

        void can_dw2_ErrorReceived(GHI.Premium.Hardware.CAN sender, GHI.Premium.Hardware.CANErrorReceivedEventArgs args)
        {
            Debug.Print("CAN error received: " + args.Error.ToString());
            
        }

        void can_dw2_DataReceived(GHI.Premium.Hardware.CAN sender, GHI.Premium.Hardware.CANDataReceivedEventArgs args)
        {
            Debug.Print("nice");
           
        }

Another question, since I have a CAN_DW module, I don’t need to define a CAN channel, right? In order to initialization a CAN with 125kb/s, I just need the following codes? Is it enough?

can_dw2.InitializeCAN(15, 8, 20);

Looking forward for your reply, I am Crazzzzzy~~~~

can I ask, under what construct are you running this program? Are you running it as a Gadgeteer app, and your code runs in the ProgramStarted() method? If so, you have a huge problem, ProgramStarted MUST end before a system can be considered initialised and therefore stable.

The second issue I see is that your sleep is woefully inadequate. You should be sleeping for 10 seconds between trying to dump out the data. I don’t know much about CAN but it could be possible you are flooding the CAN network to a point that it doesn’t react correctly. If you are truly wanting to just get CAN data received event to fire in the first instance, don’t send anything.

@ andre.m - @ Brett
Thank you for your reply.
I found that the CAN_DW is default termination off. Because I just have two nodes in the can bus now, do I need to make the termination of CAN_DW on by connect the JMP1.
http://www.ghielectronics.com/downloads/schematic/CAN-DW_Module_SCH.pdf

@ andre.m -
yes, thank you , I have read it many times.