Hello!
I'm currently working on a project that involves using an Arduino Nano 33 BLE Sense to send a CAN bus signal. For this task, I'm utilizing an MCP2515 module to manage the CAN bus communication. I've integrated the following library into my project: GitHub - 107-systems/107-Arduino-MCP2515: Arduino library for controlling the MCP2515 in order to receive/transmit CAN frames..
However, I'm encountering difficulties in successfully sending a CAN bus signal. I've provided my current code and hardware setup below for reference. It's important to note that implementing BLE functionality will come later; my primary focus at the moment is resolving the CAN bus signal issue.
Additionally, I've soldered the pads on the BLE to produce 5V. Any guidance or insights on what might be causing the problem with the CAN bus signal would be greatly appreciated. Thanks!
#include <SPI.h>
#include <ArduinoMCP2515.h>
static int const MKRCAN_MCP2515_CS_PIN = 10;
static int const MKRCAN_MCP2515_INT_PIN = 2;
//static SPISettings const MCP2515x_SPI_SETTING{10000000, MSBFIRST, SPI_MODE0};
void onReceiveBufferFull(uint32_t const timestamp_us, uint32_t const id, uint8_t const * data, uint8_t const len)
{
Serial.println(id, HEX);
}
ArduinoMCP2515 mcp2515([]() { digitalWrite(MKRCAN_MCP2515_CS_PIN, LOW); },
[]() { digitalWrite(MKRCAN_MCP2515_CS_PIN, HIGH); },
[](uint8_t const d) { return SPI.transfer(d); },
micros,
onReceiveBufferFull,
nullptr);
void setup()
{
Serial.begin(9600);
while (!Serial)
{
Serial.println("Waiting for serial connection...");
delay(100);
}
Serial.println("Serial connection established!");
// Setup SPI access
SPI.begin();
//SPI.beginTransaction(MCP2515x_SPI_SETTING);
pinMode(MKRCAN_MCP2515_CS_PIN, OUTPUT);
digitalWrite(MKRCAN_MCP2515_CS_PIN, HIGH);
attachInterrupt(digitalPinToInterrupt(MKRCAN_MCP2515_INT_PIN), [](){ mcp2515.onExternalEventHandler(); }, FALLING);
// Initialize MCP2515
mcp2515.begin();
mcp2515.setBitRate(CanBitRate::BR_250kBPS_16MHZ);
mcp2515.setNormalMode(); // Set MCP2515 to normal mode
}
void loop()
{
// Transmit a test frame
uint8_t data[4] = {0xCA, 0xFE, 0xBA, 0xBE};
if (mcp2515.transmit(0x123, data, 4)) // or mcp2515.sendMsgBuf(0x123, 0, 4, data)
{
Serial.println("Message transmitted successfully!");
}
else
{
Serial.println("Error transmitting message!");
}
delay(100);
}