Connecting Nano 33 BLE Sense to Arduino MKR CAN shield

I was trying to use Arduino Nano33 BLE Sense to send CAN messages through Arduino MKR CAN shield but it does not work. I will appreciate it if anyone has similar experiences to help me solve this problem. The hardware connection and the codes are listed below:


This figure shows how I connect the Arduino to the Shield:
5V, VCC, GND and RESET pins are connected between two boards;
CIPO is connected to CIPO;
COPI is connected to COPI;
CS(D3) of the CAN shield is connected to D3 of Nano33;
INT(D7) of the CAN shield is connected to D7 of Nano33

#include <SPI.h>

#include <ArduinoMCP2515.h>

/**************************************************************************************
 * CONSTANTS
 **************************************************************************************/

static int const MKRCAN_MCP2515_CS_PIN  = 3;
static int const MKRCAN_MCP2515_INT_PIN = 7;

/**************************************************************************************
 * FUNCTION DECLARATION
 **************************************************************************************/

void onReceiveBufferFull(uint32_t const timestamp_us, uint32_t const id, uint8_t const * data, uint8_t const len)
{
  Serial.println(id, HEX);
}

/**************************************************************************************
 * GLOBAL VARIABLES
 **************************************************************************************/

ArduinoMCP2515 mcp2515([](){ digitalWrite(MKRCAN_MCP2515_CS_PIN, LOW); },
                       [](){ digitalWrite(MKRCAN_MCP2515_CS_PIN, HIGH); },
                       [](uint8_t const d) -> uint8_t { return SPI.transfer(d); },
                       micros,
                       onReceiveBufferFull,
                       nullptr);



void setup() {
  Serial.begin(115200);
//  while(!Serial) { }

  /* Setup SPI access */
  SPI.begin();
  pinMode(MKRCAN_MCP2515_CS_PIN, OUTPUT);
  digitalWrite(MKRCAN_MCP2515_CS_PIN, HIGH);

  /* Attach interrupt handler to register MCP2515 signaled by taking INT low */
  pinMode(MKRCAN_MCP2515_INT_PIN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(MKRCAN_MCP2515_INT_PIN), [](){ mcp2515.onExternalEventHandler(); }, FALLING);

  mcp2515.begin();
  mcp2515.setBitRate(CanBitRate::BR_1000kBPS_16MHZ);
  mcp2515.setNormalMode();
}

void loop() {
  uint8_t const data1[4] = {0x00, 0x02, 0x01, 0x29};
  uint8_t const data2[4] = {0x00, 0x01, 0x01, 0x29};
  mcp2515.transmit(0x102 /* id */, data1, 4 /* len */);
  delay(5000);
  mcp2515.transmit(0x102 /* id */, data2, 4 /* len */);
  delay(5000);
}

And the script is attached above. I am using the 107-Arduino-MCP2515 library which should be compatible with both MKR WIFI 1010 and Nano 33 BLE. The script worked as expected on MKR WIFI 1010, but it seems it wasn't able to send messages on Nano 33 BLE. Does anyone know what might be the reason for that?

Problem solved. It was the 5V output of Nano 33 BLE Sense that didn't have output voltage on the 5V pin. Using Vin as the power supply for the CAN shield can solve this problem.

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