MKR CAN library - two CAN shields per MKR zero

Hi all,

I wish to use two MKR CAN shields using one MKR Zero (using two different SPI ports).
With the CAN library from Sandeep Mistry (0.3.1), this does not seem to be supported.

I do have some software experience and already adjusted the variant.h to free up sercom0 for defining the required additional SPI port.

#define SPI_INTERFACES_COUNT 3 // incremented with one

...

// SPI2
#define PIN_SPI2_MISO (21u) // PA07
#define PIN_SPI2_MOSI (11u) // PA08
#define PIN_SPI2_SCK  (12u) // PA09
#define PIN_SPI2_SS   (2u) // PA10
#define PERIPH_SPI2   sercom0 
#define PAD_SPI2_TX   SPI_PAD_0_SCK_1 
#define PAD_SPI2_RX   SERCOM_RX_PAD_3
static const uint8_t SS2 = PIN_SPI2_SS; 
static const uint8_t MOSI2 = PIN_SPI2_MOSI; 
static const uint8_t MISO2 = PIN_SPI2_MISO; 
static const uint8_t SCK2 = PIN_SPI2_SCK;

...

#define WIRE_INTERFACES_COUNT 0

...

#define I2S_INTERFACES_COUNT 0

The CAN library from Sandeep Mistry (0.3.1) does not allow to select or change the used SPI port.
Also, the library by default creates an instance of the class MCP2515Class named CAN, which is also used within the function onInterrupt().
I tried removing the creation of the instance CAN in MCP2515.cpp and change 'CAN.handleInterrupt();'to 'handleInterrupt();', but the onInterrupt() function does not allow a call to handleInterrupt without the CAN object. It gives the compile error 'cannot call member function 'void MCP2515Class::handleInterrupt()' without object'.

Any ideas?

Just to let you know, I got it to work by duplicating several files from library CAN.
The duplication allows changing the specific SPI interface used within the CAN library.
From an software architectural / reuse / maintainability point of view this is an awful solution, but it works.

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