-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 2.0.7, added Raspberry Pi Pico doc and sample code
- Loading branch information
1 parent
a57f10b
commit d6ff156
Showing
4 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
examples/LoopBackDemoRaspberryPiPico/LoopBackDemoRaspberryPiPico.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
//—————————————————————————————————————————————————————————————————————————————— | ||
// 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 to these must be set explicitly. | ||
// At the time of writing (Apr 2021) there is no official Arduino core for the Pico | ||
// Testing was done with Earle Philhower's arduino-pico core: | ||
// https://github.com/earlephilhower/arduino-pico | ||
// There is a small bug in release 1.0.3 so you will require at least 1.0.4 | ||
//—————————————————————————————————————————————————————————————————————————————— | ||
|
||
static const byte MCP2515_SCK = 2 ; // SCK input of MCP2515 | ||
static const byte MCP2515_MOSI = 3 ; // SDI input of MCP2515 | ||
static const byte MCP2515_MISO = 4 ; // SDO output of MCP2517 | ||
|
||
static const byte MCP2515_CS = 5 ; // CS input of MCP2515 (adapt to your design) | ||
static const byte MCP2515_INT = 1 ; // INT output of MCP2515 (adapt to your design) | ||
|
||
//—————————————————————————————————————————————————————————————————————————————— | ||
// 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) ; | ||
} | ||
} | ||
|
||
//—————————————————————————————————————————————————————————————————————————————— |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=ACAN2515 | ||
version=2.0.6 | ||
version=2.0.7 | ||
author=Pierre Molinaro | ||
maintainer=Pierre Molinaro <[email protected]> | ||
sentence=Driver for MCP2515 CAN Controller | ||
paragraph=Arduino CAN network driver for the MCP2515 CAN Controller. Compatible with ACAN, ACAN2517, ACAN2517FD libraries. The default configuration enables to receive all the frames. User can easily defines reception filters. Runs on ESP32 from version 1.1.2. | ||
paragraph=Arduino CAN network driver for the MCP2515 CAN Controller. Compatible with ACAN, ACAN2515Tiny, ACAN2517, ACAN2517FD libraries. The default configuration enables to receive all the frames. User can easily defines reception filters. Runs on ESP32 from version 1.1.2, on Raspberry Pi Pico. | ||
category=Communication | ||
url=https://github.com/pierremolinaro/acan2515 | ||
architectures=* |