Two mcp2515 modules on one Arduino

Hello,

I need to tap both the drive train CAN and the Infotainment CAN on a MK1 Audi TT. I can do one at a time but need to be able to tap both CAN's using a single Arduino Nano, Uno or Mega and two MCP2515's. Does anyone know how to wire & code for two MCP2515's on the same Arduino?

I'm using the mcp_can.h library and think I can probably work out the coding (declare MCP_CAN CAN0 & MCP_CAN CAN1) but it's the wiring that's confusing me as I think that the Pin assignment is specified in the mcp_can.h library?

Thanks for any tips - guidance

Any datasheet available for the 2515?

Yep,

Chip datasheet here, most of it is beyond me though,

Modules I'm using datasheet here, again most of it is beyond me,

never attempted to use two MCP2515 shields with an Arduino but do not see why it would not work
the interface is SPI which can support multiple devices - just connect the MCP2515 CS (chip Select) pins to different Arduino GPIO pins and initialise the CAN library to match

you will have two seperate CANBUS networks with CAN_H and CAN_L lines - make sure you terninate them correctly with 120ohm resisters (some CAN shields have on board termination resistors)

could you post a schematic circuit of your proposed system?

I find it is worth getting a USB-CAN dongle for a PC to monitor the CANBUS and help with debugging

Some of these modules have a defect that causes them to completely take over the SPI bus and prevent other devices from working.
If this is your case - you need to use an MCU with two SPI interfaces or connect each module through a controlled bus switch like FST3125

This is what I have at the moment, which works fine on either BUS,

Your saying use separate Arduino pins for the INT & CS for the 2nd MCP2515 and the same Arduino pins for SCK, SI & SO?

I don't know a lot about this and may be completely wrong but, might this lead to some sort of conflict between the two MCP2515 modules as far as the Arduino is concerned?

Also the speed of the 2 BUS's is different the Infotainment is 100 Kbps and the Drive Train is 500 kbps.

It looks like Profile - druckis3000 - Arduino Forum has already done this as part of his project ( Dual can bus to a single mcu )a while back but the post doesn't say how he did it, I have messaged him asking how he did it so hopefully he'll get back to me. I've also messaged Profile - coryjfowler - Arduino Forum who wrote the mcp_can.h library.

It looks like Profile - druckis3000 - Arduino Forum has already done this as part of his project ( Dual can bus to a single mcu )a while back but the post doesn't say how he did it, I have messaged him asking how he did it so hopefully he'll get back to me. I've also messaged Profile - coryjfowler - Arduino Forum who wrote the mcp_can.h library.

Yes I have done it, I can communicate on two buses at the same time. You just basically need to connect both MCP2515 modules SPI wires to Arduino in parallel, but use different CS pins and when initializing MCPs, specify correct CS pins.

This is the library that I'm using: GitHub - autowp/arduino-mcp2515: Arduino MCP2515 CAN interface library although I have modified it for my own needs. You specify CS pin in constructor.

For communication I tried using interrupt based communication, but it didn't worked. So just check for messages in main loop and process them and/or write to the bus.

By the way, since high speed is sending messages too fast, I could rarely catch messages that were necessary for me, thus, I enabled filters for high speed MCP.

Cool,

I'll give it a go, I've already found the filters are necessary.

PS
Just done some more searching and found the dual can example, don't know how I missed it before.

1 Like

Every pin is the same on the two modules except /INT and /CS. Those should be separate to individualize the MCP2515 ICs.

1 Like

Thanks,

Quick query on the interrupt pins, Am I correct in thinking the interrupt is sent from the MCP2515 to the Arduino when the MCP2515 has received a CAN message or a filtered CAN message if filtering is applied that it needs to send to the Arduino?

Also do the interrupt pin(s) on the Arduino have to be as per attachInterrupt() - Arduino Reference as I'm using pin 9 on a Nano and it's working fine?

#define CAN0_INT 9 // Set INT to pin 9
....
pinMode(9, INPUT); // Setting pin 9 for /INT input
.....
if (!digitalRead(9)) // If pin 9 is low, read receive buffer

The MCP2515 will pull the /INT pin low when a message is in either receive buffer and it remains low until all buffers are cleared.

Using attachInterrupt() is not necessary if you want to poll like the examples in the library show. I have not had much luck using the microcontroller interrupt directly and found it to not be necessary in mu use cases.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.