arduino-CAN icon indicating copy to clipboard operation
arduino-CAN copied to clipboard

Multiple CAN instances

Open reubenfinch opened this issue 5 years ago • 4 comments

There does not seem to be a way to create more than a single instance of the CAN object.

reubenfinch avatar Mar 02 '20 04:03 reubenfinch

why? you only have one on-board Can interface? SJA1000

Petros144 avatar Mar 16 '20 11:03 Petros144

@Petros144 it's a reasonable scenario, where you have multiple MCP2515s or an MCP2515 over SPI attached to an ESP32. I'm looking to do the same in order to monitor two CAN buses. Is it possible?

j4m3s avatar Jul 30 '20 20:07 j4m3s

It looks like it can be done by going down a layer and creating instances of the MCP2515 class directly. Make sure to call setPins() before begin() for the instance that's not using the default pins for chip select and interrupt.

void setup() {
  MCP2515Class CAN1;
  MCP2515Class CAN2;
  CAN1.begin(500000);
  CAN2.setPins(3,4);  //set pins to use for SPI Chip Select and CAN interupt for our second CAN controller
  CAN2.begin(500000);
}

aaknitt avatar Apr 12 '21 16:04 aaknitt

It looks like it can be done by going down a layer and creating instances of the MCP2515 class directly. Make sure to call setPins() before begin() for the instance that's not using the default pins for chip select and interrupt.

void setup() {
  MCP2515Class CAN1;
  MCP2515Class CAN2;
  CAN1.begin(500000);
  CAN2.setPins(3,4);  //set pins to use for SPI Chip Select and CAN interupt for our second CAN controller
  CAN2.begin(500000);
}

Hi. This works if using one spi lane by defining the cs and int pins. what if i want to assign the second can instance to a different lane with seperate MOSI, MISO and SCK lines?

TheCooolNerd avatar Jul 24 '22 06:07 TheCooolNerd