Arduino Giga + Arduino_CAN.h

I'm trying to integrate a CAN module (standard MCP2515 module found all over the internet) into my Arduino Giga using the AA_MCP2515.h core library. The code + module works on Arduino Uno R4, but as of yet, not on the Giga R1. CAN.begin fails.

I've tried all the CANBitrate options. I've tried 3.3v and 5v to the module. Ive tried various pins for CS. I suspect its an issue with the SPI.h library used within AA_MCP2515. I'm all out of ideas.

Anyone run into this problem before?

Here is my code:

/*
  CAN Send Example

  This will setup the CAN controller(MCP2515) to send CAN frames.
  Transmitted frames will be printed to the Serial port.
  Transmits a CAN standard frame every 2 seconds.

  MIT License
  https://github.com/codeljo/AA_MCP2515
*/

#include "AA_MCP2515.h"

// TODO: modify CAN_BITRATE, CAN_PIN_CS(Chip Select) pin, and CAN_PIN_INT(Interrupt) pin as required.
const CANBitrate::Config CAN_BITRATE = CANBitrate::Config_8MHz_250kbps;
const uint8_t CAN_PIN_CS = 10;
const int8_t CAN_PIN_INT = 2;

CANConfig config(CAN_BITRATE, CAN_PIN_CS, CAN_PIN_INT);
CANController CAN(config);

uint8_t data[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };

void setup() {
  Serial.begin(115200);

  while(CAN.begin(CANController::Mode::Normal) != CANController::OK) {
    Serial.println("CAN begin FAIL - delaying for 1 second");
    delay(100);
  }
  Serial.println("CAN begin OK");
}

void loop() {

  // transmit
  CANFrame frame(0x100, data, sizeof(data));
  CAN.write(frame);
  frame.print("CAN TX");

  // modify data to simulate updated data from sensor, etc
  data[0] += 1;

  delay(10000);
}

Hi Jed, are you connecting to the correct SPI pins? The GIGA has two SPI interfaces:

// SPI
#define PIN_SPI_MISO  (89u)
#define PIN_SPI_MOSI  (90u)
#define PIN_SPI_SCK   (91u)
// Same as SPI1 for backwards compatibility
#define PIN_SPI_SS    (10u)

#define PIN_SPI_MISO1  (12u)
#define PIN_SPI_MOSI1  (11u)
#define PIN_SPI_SCK1   (13u)
#define PIN_SPI_SS1    (10u)

For SPI it's the pins in the middle of the board, for SPI1 it's the ones on the edge. Apologies if you're already aware. The library will no doubt expect SPI

1 Like

Nope. Just using trusty ole 10, 11, 12, 13 and 2. I'll try these out and keep you posted

Thank you!

A quick check of the lib and the SPI can be overridden

CANConfig(CANBitrate::Config bitrate_config, uint8_t cs_pin, int8_t int_pin, SPIClass& spi = SPI, uint32_t spi_hz = DEFAULT_SPI_HZ) :

If you want the trusty pins, try specifying SPI1 in the config call.

Oh nice! Barring a false positive, that appears to have resolved the CAN.begin() error. Thank you

Now Im trying to do some sanity checks by sending some test messages to my bus where a different Arduino's (Uno R4) on the other end as the receiver. So far I'm not seeing any messages roll in, but the issue is likely something stupid in the R4 code. I'll be able to check it with a scope in a couple days.

Thank you again