Bon, j'avance. En fait, je n'ai le problème que lorsque j'affecte les pins qu'il me semble que tu as choisies sur ton montage :
static const byte MCP2515_INT = 9; // INT output of MCP2515
static const byte MCP2515_SCK = 10; // SCK input of MCP2515
static const byte MCP2515_MOSI = 11; // SI input of MCP2515
static const byte MCP2515_MISO = 12; // SO output of MCP2515
static const byte MCP2515_CS = 13; // CS input of MCP2515
Quand je joue le sketch de démo loopBackDemoRaspberryPicoPi (non modifié) je n'ai pas de problème. Mais si je met cette affectation de pins, ça plante :
//——————————————————————————————————————————————————————————————————————————————
// ACAN2515 Demo in loopback mode, for the Raspberry Pi Pico
// Thanks to Duncan Greenwood for providing this sample sketch
//——————————————————————————————————————————————————————————————————————————————
#ifndef ARDUINO_ARCH_RP2040
#error "Select a Raspberry Pi Pico board"
#endif
//——————————————————————————————————————————————————————————————————————————————
#include <ACAN2515.h>
//——————————————————————————————————————————————————————————————————————————————
// The Pico has two SPI peripherals, SPI and SPI1. Either (or both) can be used.
// The are no default pin assignments so they must be set explicitly.
// Testing was done with Earle Philhower's arduino-pico core:
// https://github.com/earlephilhower/arduino-pico
//——————————————————————————————————————————————————————————————————————————————
static const byte MCP2515_INT = 9; // INT output of MCP2515
static const byte MCP2515_SCK = 10; // SCK input of MCP2515
static const byte MCP2515_MOSI = 11; // SI input of MCP2515
static const byte MCP2515_MISO = 12; // SO output of MCP2515
static const byte MCP2515_CS = 13; // CS input of MCP2515
//——————————————————————————————————————————————————————————————————————————————
// MCP2515 Driver object
//——————————————————————————————————————————————————————————————————————————————
ACAN2515 can (MCP2515_CS, SPI, MCP2515_INT) ;
//——————————————————————————————————————————————————————————————————————————————
// MCP2515 Quartz: adapt to your design
//——————————————————————————————————————————————————————————————————————————————
static const uint32_t QUARTZ_FREQUENCY = 20UL * 1000UL * 1000UL ; // 20 MHz
//——————————————————————————————————————————————————————————————————————————————
// SETUP
//——————————————————————————————————————————————————————————————————————————————
void setup () {
//--- Switch on builtin led
pinMode (LED_BUILTIN, OUTPUT) ;
digitalWrite (LED_BUILTIN, HIGH) ;
//--- Start serial
Serial.begin (115200) ;
//--- Wait for serial (blink led at 10 Hz during waiting)
while (!Serial) {
delay (50) ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
}
//--- There are no default SPI pins so they must be explicitly assigned
SPI.setSCK(MCP2515_SCK);
SPI.setTX(MCP2515_MOSI);
SPI.setRX(MCP2515_MISO);
SPI.setCS(MCP2515_CS);
//--- Begin SPI
SPI.begin () ;
//--- Configure ACAN2515
Serial.println ("Configure ACAN2515") ;
ACAN2515Settings settings (QUARTZ_FREQUENCY, 125UL * 1000UL) ; // CAN bit rate 125 kb/s
settings.mRequestedMode = ACAN2515Settings::LoopBackMode ; // Select loopback mode
const uint16_t errorCode = can.begin (settings, [] { can.isr () ; }) ;
if (errorCode == 0) {
Serial.print ("Bit Rate prescaler: ") ;
Serial.println (settings.mBitRatePrescaler) ;
Serial.print ("Propagation Segment: ") ;
Serial.println (settings.mPropagationSegment) ;
Serial.print ("Phase segment 1: ") ;
Serial.println (settings.mPhaseSegment1) ;
Serial.print ("Phase segment 2: ") ;
Serial.println (settings.mPhaseSegment2) ;
Serial.print ("SJW: ") ;
Serial.println (settings.mSJW) ;
Serial.print ("Triple Sampling: ") ;
Serial.println (settings.mTripleSampling ? "yes" : "no") ;
Serial.print ("Actual bit rate: ") ;
Serial.print (settings.actualBitRate ()) ;
Serial.println (" bit/s") ;
Serial.print ("Exact bit rate ? ") ;
Serial.println (settings.exactBitRate () ? "yes" : "no") ;
Serial.print ("Sample point: ") ;
Serial.print (settings.samplePointFromBitStart ()) ;
Serial.println ("%") ;
} else {
Serial.print ("Configuration error 0x") ;
Serial.println (errorCode, HEX) ;
}
}
//----------------------------------------------------------------------------------------------------------------------
static uint32_t gBlinkLedDate = 0 ;
static uint32_t gReceivedFrameCount = 0 ;
static uint32_t gSentFrameCount = 0 ;
//——————————————————————————————————————————————————————————————————————————————
void loop () {
CANMessage frame ;
if (gBlinkLedDate < millis ()) {
gBlinkLedDate += 2000 ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
const bool ok = can.tryToSend (frame) ;
if (ok) {
gSentFrameCount += 1 ;
Serial.print ("Sent: ") ;
Serial.println (gSentFrameCount) ;
} else {
Serial.println ("Send failure") ;
}
}
if (can.available ()) {
can.receive (frame) ;
gReceivedFrameCount ++ ;
Serial.print ("Received: ") ;
Serial.println (gReceivedFrameCount) ;
}
}
//——————————————————————————————————————————————————————————————————————————————