Automotive and Embedded Networks

cancel
Showing results for 
Search instead for 
Did you mean: 

NI 9862 CAN module communication with MCP2515

Solved!
Go to solution

Hi everyone,

This is my first post to this group. 

 

To learn more about XNET drivers, I did an HW set up in the lab using NI CRIO-9054 with NI 9862 CAN module and (MCP2515 CAN board + Arduino).

So, here I am trying to read CAN data sent by MCP2515+arduino to NI 9862 module. To quickly test the communication, I used the NI XNET bus monitor. I have powered NI 9862 VSUP pin with +12 external supply which is working fine and tested communication using XNET. blink function which turns on 9862 onboard LEDs.

The CAN_write.ino is a simple code that sends fixed CAN data continuously.

#Issue: In the NI XNET bus monitor after starting a session, I am not getting any data.

-----------------------------------------------------------------------------------------------------------------------

A quick overview of the setup.

1. In the Arduino code, the MCP2215 bitrate is set to 125Kbps. (Also tried with different Baud rates, but no data received). Arduino CAN library used - https://github.com/autowp/arduino-mcp2515 

2. In the NI XNET bus monitor is kept the same as in the Arduino code.

3. CANH (Orange wire) and CANL(chocolate color wire) of MCP2515 is connected to 9862 CAN H and CANL

4. Red and Black wire supplies +12Vdc to 9862 Vsup pin

5. I have used NI CAN cable without termination initially, with Software "Termination" option checked in NI xnet bus monitor to use NI 9862 onboard termination and I have placed a termination jumper on the MCP2515(It can be seen as side pins shorted next to CANH and CANL). So, I believe after this termination is done on CAN bus. Still not got any data. Is anything wrong with this setup? any idea?

6. Then I used CAN cable with termination, but no data again. I know NI 9862 has onboard termination which is software selectable, So is there any need to use a cable with termination?

 

I saw similar posts with MCP2515 and NI-CAN but didn't find relevant info.

Need thoughts on above. 

PFA. images for reference and Arduino code.CAN cable with terminationCAN cable with terminationNI XNET BUS MonitorNI XNET BUS MonitorNI_XNET 3.jpg+12V to NI 9862 Vsup and CANH_L connection+12V to NI 9862 Vsup and CANH_L connectionNO dataNO datasetupsetupSide two pinsSide two pinsarduino-mcp2515-can-bus-interface-mcp2515-can-module-components.jpg

#include <SPI.h>
#include <mcp2515.h>

struct can_frame canMsg1;
struct can_frame canMsg2;
MCP2515 mcp2515(10);


void setup() {
  canMsg1.can_id  = 0x0F6;
  canMsg1.can_dlc = 8;
  canMsg1.data[0] = 0x8E;
  canMsg1.data[1] = 0x87;
  canMsg1.data[2] = 0x32;
  canMsg1.data[3] = 0xFA;
  canMsg1.data[4] = 0x26;
  canMsg1.data[5] = 0x8E;
  canMsg1.data[6] = 0xBE;
  canMsg1.data[7] = 0x86;
  
  while (!Serial);
  Serial.begin(115200);
  
  mcp2515.reset();
  mcp2515.setBitrate(CAN_125KBPS);
  mcp2515.setNormalMode();
  
  Serial.println("Example: Write to CAN");
}

void loop() {
  mcp2515.sendMessage(&canMsg1);

  Serial.println("Messages sent");
  
  delay(1000);
}
0 Kudos
Message 1 of 10
(5,974 Views)

Seems like a pretty simple setup but there are still places that there could be issues.

 

First make sure you CAN H is wired to CAN H and CAN L is wired to CAN L.  This might be obvious to some, but CAN wires all the high lines together, and all the Low lines together.  This isn't like serial where the TX and RX need to be swapped.  I mention this in Part 1 of the blog here.

 

So this means in your setup the brown wire should go to pin 2 on the DB9, and the orange should be pin 7 on the DB9.  And then it looks like the 12V+ should be pin 9 and negative be pin 1, but I didn't look up the model of your card so it might be different.

 

As for termination you should have a total of 2 resistors of 120ohms.  But in most cases a single will work too, but having 0 almost always fails.  So if you have it enabled in the XNet software, and have it enabled in one other place you should be fine.  

 

In the bus monitor I can't see the baud rate settings.  But when it isn't running click the configure button and make sure that the baud rate matches which right now looks like 125K.\

 

If the issue is on the Arduino side it might be difficult to troubleshoot.  I'd try to put a scope between the CAN H and CAN L lines and see if it bounces as the Arduino writes data.  It is possible there are errors and your C code isn't reading any.  Like if you completely unplug the 2515 I think you won't notice any difference.  I've seen examples in the past that check for errors after each command like setting the baud.

0 Kudos
Message 2 of 10
(5,954 Views)

Hi, Hoovahhh,

 

Thank you for sharing your thoughts. So, today I did some in-depth work considering your suggestions:

 

PFA, PDF. I have recorded all of my observations in this.

 

I looked into your CAN series blog it's a really good starting point. Studying it.

Hope to get your suggestions on this.

If this setup worked, then I can start making an XNET library to use in different projects and will be able to test APIs. So, getting this done is important now. Cheers! 😄

 

 

 

0 Kudos
Message 3 of 10
(5,923 Views)

All of that seems right.  The fact that you have two Arduinos talking is a good sign.  Error frames means the NI card is seeing voltages change, but can't determine what the CAN data is.  This is typically a problem when there baud rates that don't match, but it seems you've checked that.  I've never ran at some of those weird bauds before, I'd stick to 250k or 500k.  Still I don't think that is your problem.  Sorry I don't have any more suggestions, I'd expect it to work.

0 Kudos
Message 4 of 10
(5,904 Views)

Well, here are some queries:

 

1. Since NI 9862 VSUP+ takes +9V to +30V supply to power on its transreciever while MCP2515 runs on 5V supply. So, I guess this shouldn't be the issue, considering CAN_H and CAN_L bus are isolated. Any tell me if am wrong?

 

2. Regarding using 120ohms termination, Does it necessary to always have termination enabled either in the software interface or directly in hardware? 

   1. Two pairs of ( MCP2515+Arduino ) are communicating without the Termination jumper placed.

   2. I used NI-recommended CAN Cable with internal 120ohms resistance, Also tried enabling in XNET bus monitor and placed 120ohms jumper on MCP2515. I guess, these are recommended hardware connections to avoid reflections on CAN_H and CAN_L bus. So this should wrong fine. Any thoughts? 

 FYI, the Arduino can library i used does support most often used baud rates of 250KBPS/500KBPS. 

 

3. Can you suggest any CAN sensor other than MCP2515 you used before which runs on 5V supply? So that i can check. 

 

Thanks!

0 Kudos
Message 5 of 10
(5,899 Views)

@Voyager7277 wrote:

Well, here are some queries:

 

1. Since NI 9862 VSUP+ takes +9V to +30V supply to power on its transreciever while MCP2515 runs on 5V supply. So, I guess this shouldn't be the issue, considering CAN_H and CAN_L bus are isolated. Any tell me if am wrong?


Power it with a DC supply between 9V and 30V, Pins 9 for positive, and 3 or 6 for negative on the DB 9 of the 9862.  But like you said it isn't complaining in the bus monitor that it isn't powered so I'd suspect it is correct.

 


2. Regarding using 120ohms termination, Does it necessary to always have termination enabled either in the software interface or directly in hardware? 


You can get lucky and things work with or without them.  But to avoid issues just have 2 of the 120 ohm resistors in the circuit.  If you have one enabled in the bus monitor, then have it in one more place.  If it already is in the DB9 harness, then that is your second one.  

0 Kudos
Message 6 of 10
(5,893 Views)

2. for 120 ohms,

            1. Yes, I am keeping Termination enabled in XNET bus monitor to enable NI 9862 onboard 120 ohms terminations.

             2. Yes, I am using NI CAN Cable with a builtin 120-ohm resistor.

Also, MCP2515 120ohm termination pins are shorted.

 

Seems this should be fine. But unable to get it. I guess need to give it a try again while keeping 250 or 500KBPS baud rates only.

 

Thanks! I will keep you posted.

 

0 Kudos
Message 7 of 10
(5,891 Views)
Solution
Accepted by Voyager7277

Hi Hoovahh,

 

FYI, After debugging a bit, I found the solution, and Now the CAN communication is working fine.

Able to Transmit CAN frames from NI 9862 to MCP2515 and Vice-versa.

 

PFA, Solution.PDF (Ref Pg. no - 11)

Now I can actually test XNET APIs...

 

Thanks! for all your insights. Will keep you posted.

0 Kudos
Message 8 of 10
(5,871 Views)
0 Kudos
Message 9 of 10
(5,866 Views)

Hi,

 

There is a function "MCP.setbitrate(125KBPS)"  in setup() in both CAN_Write.ino and _Read.ino. As per the examples, this above func() takes only argument i.e setting bit rate in KBPS. But there is another argument to set MCP2515 internal clock to either 8/16/32MHZ. 

By default: .setbitrate() takes 2nd argument as 16MHZ clock frequency as i was digged into .cpp and .h files.

but this setting worked with two MCP2515 chips as I showed earlier but not with NI 9862 though.

Well, today did some web search and found setting MCP clock to 8MHZ in .setbitrate function() and it worked consistently afterward. 

Also, the MCP2515 breakout board has an onboard crystal clock of 8MHZ only. Ref.MCP2515 board with 8MHZ crystal clock onboardMCP2515 board with 8MHZ crystal clock onboard

 

 

Message 10 of 10
(5,862 Views)