Author SHA1 Message Date
pillar1989 34c1d6ff91 fix: use pSPI->begin() and add skipSpiBegin option for ESP32 compatibility
ESP32 users need to call SPI.begin() with custom pin assignments before
using the library (GPIO matrix). The hardcoded SPI.begin() in
mcp2518fd::begin() overwrites this configuration.

Changes:
- Replace SPI.begin() with pSPI->begin() (consistent with MCP2515)
- Add optional _initSPI parameter (default true) to begin() across
  MCP_CAN, mcp2515, and mcp2518fd so ESP32 users can skip SPI init

Existing code is unaffected — default behavior unchanged.

Closes #158
2026-05-26 11:20:23 +08:00
alias pillar1989andGitHub ca8fcc7fe3 Add MCP2515 8MHz 83.3kbps bitrate support
Add the missing MCP_8MHz_83k3BPS timing macros and wire CAN_83K3BPS into the MCP_8MHz bitrate switch. Fixes #79.
2026-04-28 11:09:23 +08:00
yuan_mo 31438c426b add send and receive extended frames examples 2025-04-21 09:48:53 +08:00
ShuishengPengandGitHub ad48756e56 Merge pull request #153 from techie66/bugfix_140
Change order of TX buffer fill to ensure in-order sending of frames.
2025-02-06 10:22:56 +08:00
Jacob Geigle c8556d5c1b Change order of TX buffer fill to ensure in-order sending of frames. 2025-02-02 11:45:28 -05:00
Lesords 23b23eff5c ci: add an action to automatically close stale issues and PRs 2025-01-08 07:43:42 +00:00
ackPeng 6f556e2ac8 add run-cl-arduino.yml and add SERIAL_PORT_MONITOR define 2024-12-27 14:48:26 +08:00
Matthew 491283753f Add sync_issues GitHub Action for workflows 2024-10-08 18:24:20 +08:00
EthanethiolandGitHub 23666a81df Added MCP_8MHz_95k2BPS (#150) 2024-03-18 09:06:42 +08:00
Micah MundyandGitHub 6dcfabc65e Patch four-argument sendmsgbuf (#146)
maintains backward compatibility with previous versions of
the function call
2023-08-09 08:23:01 +08:00
Pasakorn TiwatthanontandGitHub 02d18fb3b3 Reset rx overflow flag (#144) 2023-06-01 08:54:16 +08:00
JaxonandGitHub 7328966ef0 Merge pull request #139 from Maxwelltoo/master
fix subclass reference error
2023-01-10 10:30:59 +08:00
Jaxon adceb9b415 fix subclass reference error 2023-01-10 10:24:18 +08:00
Micah MundyandGitHub eb6887ba3c Move the four-argument sendMsgBuf wrapper to mcp_can.h (#136) 2022-08-30 13:44:00 +08:00
Lakshantha Dissanayake b946ae7c24 Update: library.json and library.properties 2022-04-11 23:38:18 +05:30
18 changed files with 424 additions and 29 deletions
+87
View File
@@ -0,0 +1,87 @@
name: Run Ci Arduino
on:
push:
pull_request:
repository_dispatch:
types: [trigger-workflow]
jobs:
ci-arduino:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout script repository
uses: actions/checkout@v4
with:
repository: Seeed-Studio/ci-arduino
path: ci
- name: Setup arduino cli
uses: arduino/setup-arduino-cli@v2.0.0
- name: Create a depend.list file
run: |
# eg: echo "<repo>" >> depend.list
echo "arduino-libraries/SD" >> depend.list
echo "frankjoshua/rosserial_arduino_lib" >> depend.list
- name: Create a ignore.list file
run: |
# eg: echo "<path>,<fqbn>" >> ignore.list
# ROS library has some issue with std_msg, so we ignore them,waiting for the fix
echo "send_Blink_ROS,Seeeduino:samd:seeed_XIAO_m0" >> ignore.list
echo "send_Blink_ROS,Seeeduino:nrf52:xiaonRF52840" >> ignore.list
echo "send_Blink_ROS,Seeeduino:nrf52:xiaonRF52840Sense" >> ignore.list
echo "send_Blink_ROS,Seeeduino:renesas_uno:XIAO_RA4M1" >> ignore.list
echo "send_Blink_ROS,rp2040:rp2040:seeed_xiao_rp2040" >> ignore.list
echo "send_Blink_ROS,rp2040:rp2040:seeed_xiao_rp2350" >> ignore.list
echo "send_Blink_ROS,esp32:esp32:XIAO_ESP32C3" >> ignore.list
echo "send_Blink_ROS,esp32:esp32:XIAO_ESP32C6" >> ignore.list
echo "send_Blink_ROS,esp32:esp32:XIAO_ESP32S3" >> ignore.list
echo "receive_sleep,Seeeduino:samd:seeed_XIAO_m0" >> ignore.list
echo "receive_sleep,Seeeduino:nrf52:xiaonRF52840" >> ignore.list
echo "receive_sleep,Seeeduino:nrf52:xiaonRF52840Sense" >> ignore.list
echo "receive_sleep,Seeeduino:renesas_uno:XIAO_RA4M1" >> ignore.list
echo "receive_sleep,rp2040:rp2040:seeed_xiao_rp2040" >> ignore.list
echo "receive_sleep,rp2040:rp2040:seeed_xiao_rp2350" >> ignore.list
echo "receive_sleep,esp32:esp32:XIAO_ESP32C3" >> ignore.list
echo "receive_sleep,esp32:esp32:XIAO_ESP32C6" >> ignore.list
echo "receive_sleep,esp32:esp32:XIAO_ESP32S3" >> ignore.list
echo "send_sleep,Seeeduino:samd:seeed_XIAO_m0" >> ignore.list
echo "send_sleep,Seeeduino:nrf52:xiaonRF52840" >> ignore.list
echo "send_sleep,Seeeduino:nrf52:xiaonRF52840Sense" >> ignore.list
echo "send_sleep,Seeeduino:renesas_uno:XIAO_RA4M1" >> ignore.list
echo "send_sleep,rp2040:rp2040:seeed_xiao_rp2040" >> ignore.list
echo "send_sleep,rp2040:rp2040:seeed_xiao_rp2350" >> ignore.list
echo "send_sleep,esp32:esp32:XIAO_ESP32C3" >> ignore.list
echo "send_sleep,esp32:esp32:XIAO_ESP32C6" >> ignore.list
echo "send_sleep,esp32:esp32:XIAO_ESP32S3" >> ignore.list
- name: Build sketch
run: ./ci/tools/compile.sh
- name: Build result
run: |
cat build.log
if [ ${{ github.event_name }} == 'pull_request' ] && [ -f compile.failed ]; then
exit 1
fi
- name: Generate issue
if: ${{ github.event_name != 'pull_request' }}
run: ./ci/tools/issue.sh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+25
View File
@@ -0,0 +1,25 @@
name: 'Close stale issues and PRs'
on:
workflow_dispatch:
schedule:
- cron: '0 4 * * *'
jobs:
stale:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout script repository
uses: actions/checkout@v4
with:
repository: Seeed-Studio/sync-github-all-issues
path: ci
- name: Run script
run: ./ci/tools/stale.sh
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+24
View File
@@ -0,0 +1,24 @@
name: Automate Issue Management
on:
issues:
types:
- opened
- edited
- assigned
- unassigned
- labeled
- unlabeled
- reopened
jobs:
add_issue_to_project:
runs-on: ubuntu-latest
steps:
- name: Add issue to GitHub Project
uses: actions/add-to-project@v1.0.2
with:
project-url: https://github.com/orgs/Seeed-Studio/projects/17
github-token: ${{ secrets.ISSUE_ASSEMBLE }}
labeled: bug
label-operator: NOT
@@ -48,7 +48,13 @@ void setup() {
}
SERIAL_PORT_MONITOR.println("CAN init ok!");
byte mode = CAN.getMode();
#ifdef ARDUINO_XIAO_RA4M1
char buffer[50];
sprintf(buffer, "CAN BUS mode = %d\n\r", mode);
SERIAL_PORT_MONITOR.print(buffer);
#else
SERIAL_PORT_MONITOR.printf("CAN BUS mode = %d\n\r", mode);
#endif
}
void MCP2515_ISR() {
@@ -0,0 +1,124 @@
// This is an example of receiving both standard frames and extended frames simultaneously.
// I have used two arrays, STANDARD_CAN_IDS and EXTENDED_CAN_IDS, to receive CAN messages with specific IDs.
// You need to set filters and masks for these IDs,
// and make sure to refer to and coordinate with the example for sending extended frames
#include <SPI.h>
#define CAN_2515
// #define CAN_2518FD
// Set SPI CS Pin according to your hardware
#if defined(SEEED_WIO_TERMINAL) && defined(CAN_2518FD)
// For Wio Terminal w/ MCP2518FD RPi Hat
// Channel 0 SPI_CS Pin: BCM 8
// Channel 1 SPI_CS Pin: BCM 7
// Interupt Pin: BCM25
const int SPI_CS_PIN = BCM8;
const int CAN_INT_PIN = BCM25;
#else
// For Arduino MCP2515 Hat:
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;
#endif
#ifdef CAN_2518FD
#include "mcp2518fd_can.h"
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
#endif
#ifdef CAN_2515
#include "mcp2515_can.h"
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
#endif
// Define the list of standard CAN IDs to receive
const unsigned long STANDARD_CAN_IDS[] = {0x123, 0x456};
const int STANDARD_CAN_ID_COUNT = sizeof(STANDARD_CAN_IDS) / sizeof(STANDARD_CAN_IDS[0]);
// Define the list of extended CAN IDs to receive
const unsigned long EXTENDED_CAN_IDS[] = {0x1234567, 0x89ABCDE};
const int EXTENDED_CAN_ID_COUNT = sizeof(EXTENDED_CAN_IDS) / sizeof(EXTENDED_CAN_IDS[0]);
void setup()
{
SERIAL_PORT_MONITOR.begin(115200);
while(!Serial){};
while (CAN_OK != CAN.begin(CAN_250KBPS))
{ // init can bus : baudrate = 250k
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
delay(100);
}
SERIAL_PORT_MONITOR.println("CAN init ok!");
// Configure the standard frame filters
for (int i = 0; i < STANDARD_CAN_ID_COUNT; i++)
{
CAN.init_Mask(i, 0, 0x7FF); // Check all 11 bits of the standard frame
CAN.init_Filt(i, 0, STANDARD_CAN_IDS[i]);
}
// Configure the extended frame filters
for (int i = 0; i < EXTENDED_CAN_ID_COUNT; i++)
{
CAN.init_Mask(i + STANDARD_CAN_ID_COUNT, 1, 0x1FFFFFFF); // Check all 29 bits of the extended frame
CAN.init_Filt(i + STANDARD_CAN_ID_COUNT, 1, EXTENDED_CAN_IDS[i]);
}
}
void loop()
{
unsigned char len = 0;
unsigned char buf[8];
if (CAN_MSGAVAIL == CAN.checkReceive())
{ // check if data coming
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
unsigned long canId = CAN.getCanId();
// Check if it is a standard CAN ID
for (int i = 0; i < STANDARD_CAN_ID_COUNT; i++)
{
if (canId == STANDARD_CAN_IDS[i])
{
SERIAL_PORT_MONITOR.println("-----------------------------");
SERIAL_PORT_MONITOR.print("Get standard data from ID: 0x");
SERIAL_PORT_MONITOR.println(canId, HEX);
for (int j = 0; j < len; j++)
{ // print the data
SERIAL_PORT_MONITOR.print(buf[j], HEX);
SERIAL_PORT_MONITOR.print("\t");
}
SERIAL_PORT_MONITOR.println();
break;
}
}
// Check if it is an extended CAN ID
for (int i = 0; i < EXTENDED_CAN_ID_COUNT; i++)
{
if (canId == EXTENDED_CAN_IDS[i])
{
SERIAL_PORT_MONITOR.println("-----------------------------");
SERIAL_PORT_MONITOR.print("Get extended data from ID: 0x");
SERIAL_PORT_MONITOR.println(canId, HEX);
for (int j = 0; j < len; j++)
{ // print the data
SERIAL_PORT_MONITOR.print(buf[j], HEX);
SERIAL_PORT_MONITOR.print("\t");
}
SERIAL_PORT_MONITOR.println();
break;
}
}
}
}
+2 -2
View File
@@ -4,8 +4,8 @@
#include <SPI.h>
#define CAN_2515
// #define CAN_2518FD
//#define CAN_2515
#define CAN_2518FD
// Set SPI CS Pin according to your hardware
+2 -2
View File
@@ -1,8 +1,8 @@
// demo: CAN-BUS Shield, send data
#include <SPI.h>
#define CAN_2515
// #define CAN_2518FD
//#define CAN_2515
#define CAN_2518FD
// Set SPI CS Pin according to your hardware
@@ -0,0 +1,93 @@
// demo: CAN-BUS Shield, send data
// This is an example of sending both standard frames and extended frames simultaneously.
// I have used two arrays, STANDARD_CAN_IDS and EXTENDED_CAN_IDS, to store the IDs to be sent, and it supports defining custom send IDs
#include <SPI.h>
#define CAN_2515
// #define CAN_2518FD
// Set SPI CS Pin according to your hardware
#if defined(SEEED_WIO_TERMINAL) && defined(CAN_2518FD)
// For Wio Terminal w/ MCP2518FD RPi Hat
// Channel 0 SPI_CS Pin: BCM 8
// Channel 1 SPI_CS Pin: BCM 7
// Interupt Pin: BCM25
const int SPI_CS_PIN = BCM8;
const int CAN_INT_PIN = BCM25;
#else
// For Arduino MCP2515 Hat:
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;
#endif
#ifdef CAN_2518FD
#include "mcp2518fd_can.h"
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
#endif
#ifdef CAN_2515
#include "mcp2515_can.h"
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
#endif
// Define the list of standard CAN IDs to receive
const unsigned long STANDARD_CAN_IDS[] = {0x123, 0x456};
const int STANDARD_CAN_ID_COUNT = sizeof(STANDARD_CAN_IDS) / sizeof(STANDARD_CAN_IDS[0]);
// Define the list of extended CAN IDs to receive
const unsigned long EXTENDED_CAN_IDS[] = {0x1234567, 0x89ABCDE};
const int EXTENDED_CAN_ID_COUNT = sizeof(EXTENDED_CAN_IDS) / sizeof(EXTENDED_CAN_IDS[0]);
void setup()
{
SERIAL_PORT_MONITOR.begin(115200);
while(!Serial){};
while (CAN_OK != CAN.begin(CAN_500KBPS))
{ // init can bus : baudrate = 500k
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
delay(100);
}
SERIAL_PORT_MONITOR.println("CAN init ok!");
}
unsigned char stmp[8] = {0, 0, 0, 0, 0, 0, 0, 0};
void loop()
{
// send data: id = 0x00, standrad frame, data len = 8, stmp: data buf
stmp[7] = stmp[7] + 1;
if (stmp[7] == 100)
{
stmp[7] = 0;
stmp[6] = stmp[6] + 1;
if (stmp[6] == 100)
{
stmp[6] = 0;
stmp[5] = stmp[5] + 1;
}
}
for (int i = 0; i < STANDARD_CAN_ID_COUNT; i++)
{
CAN.sendMsgBuf(STANDARD_CAN_IDS[i], 0, 8, stmp);//using ID List ID
delay(100);
}
for (int i = 0; i < EXTENDED_CAN_ID_COUNT; i++)
{
CAN.sendMsgBuf(EXTENDED_CAN_IDS[i], 1, 8, stmp);//using ID List ID
delay(100);
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
+1
View File
@@ -36,6 +36,7 @@ CAN_50KBPS LITERAL1
CAN_80KBPS LITERAL1
CAN_83K3BPS LITERAL1
CAN_95KBPS LITERAL1
CAN_95K2BPS LITERAL1
CAN_100KBPS LITERAL1
CAN_125KBPS LITERAL1
CAN_200KBPS LITERAL1
+3 -3
View File
@@ -1,13 +1,13 @@
{
"name": "CAN_BUS_Shield",
"keywords": "can, bus, mcp2518fd, mcp2515, mcp-2515",
"description": "Seeed Arduino library to control CAN-BUS and CAN BUS FD.",
"keywords": "can, bus, mcp2518fd, mcp2515",
"description": "Seeed Arduino library to control CAN BUS and CAN BUS FD.",
"repository":
{
"type": "git",
"url": "https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git"
},
"version": "2.3.2",
"version": "2.3.3",
"frameworks": "arduino",
"platforms": "*"
}
+4 -4
View File
@@ -1,9 +1,9 @@
name=CAN-BUS Shield
version=2.3.2
name=CAN_BUS_Shield
version=2.3.3
author=Seeed Studio
maintainer=Seeed Studio <techsupport@seeed.cc>
sentence=Seeed Arduino library to control CAN-BUS and CAN BUS FD.
paragraph=Seeed Arduino library to control CAN-BUS and CAN BUS FD.
sentence=Seeed Arduino library to control CAN BUS and CAN BUS FD.
paragraph=Seeed Arduino library to control CAN BUS and CAN BUS FD.
category=Device Control
url=https://github.com/Seeed-Studio/Seeed_Arduino_CAN
architectures=*
+1 -1
View File
@@ -211,7 +211,7 @@ private:
INT8U openCanBus();
INT8U sendMsgBuf(INT32U id, INT8U ext, INT8U rtr, INT8U len, INT8U *buf);
void parseCanStdId();
void parseCanExtId();
};
+16 -3
View File
@@ -680,6 +680,18 @@ byte mcp2515_can::mcp2515_configRate(const byte canSpeed, const byte clock) {
cfg3 = MCP_8MHz_80kBPS_CFG3;
break;
case (CAN_83K3BPS) :
cfg1 = MCP_8MHz_83k3BPS_CFG1;
cfg2 = MCP_8MHz_83k3BPS_CFG2;
cfg3 = MCP_8MHz_83k3BPS_CFG3;
break;
case (CAN_95K2BPS):
cfg1 = MCP_8MHz_95k2BPS_CFG1;
cfg2 = MCP_8MHz_95k2BPS_CFG2;
cfg3 = MCP_8MHz_95k2BPS_CFG3;
break;
case (CAN_100KBPS) :
cfg1 = MCP_8MHz_100kBPS_CFG1;
cfg2 = MCP_8MHz_100kBPS_CFG2;
@@ -1032,7 +1044,7 @@ byte mcp2515_can::mcp2515_getNextFreeTXBuf(byte* txbuf_n) { // get
}
// check all 3 TX-Buffers except reserved
for (i = 0; i < MCP_N_TXBUFFERS - nReservedTx; i++) {
for (i = MCP_N_TXBUFFERS - nReservedTx; i >= 0; i--) {
if ((status & txStatusPendingFlag(i)) == 0) {
*txbuf_n = txCtrlReg(i) + 1; // return SIDH-address of Buffer
mcp2515_modifyRegister(MCP_CANINTF, txIfFlag(i), 0);
@@ -1046,8 +1058,8 @@ byte mcp2515_can::mcp2515_getNextFreeTXBuf(byte* txbuf_n) { // get
** Function name: begin
** Descriptions: init can and set speed
*********************************************************************************************************/
byte mcp2515_can::begin(uint32_t speedset, const byte clockset) {
pSPI->begin();
byte mcp2515_can::begin(uint32_t speedset, const byte clockset, const bool _initSPI) {
if (_initSPI) pSPI->begin();
byte res = mcp2515_init((byte)speedset, clockset);
return ((res == MCP2515_OK) ? CAN_OK : CAN_FAILINIT);
@@ -1396,6 +1408,7 @@ byte mcp2515_can::checkReceive(void) {
*********************************************************************************************************/
byte mcp2515_can::checkError(uint8_t* err_ptr) {
byte eflg = mcp2515_readRegister(MCP_EFLG);
mcp2515_modifyRegister(MCP_EFLG, 0xFF, 0);
if (err_ptr) {
*err_ptr = eflg;
}
+2 -5
View File
@@ -69,7 +69,7 @@ public:
{
return MCP_N_TXBUFFERS - 1; // read index of last tx buffer
}
virtual byte begin(uint32_t speedset, const byte clockset = MCP_16MHz); // init can
virtual byte begin(uint32_t speedset, const byte clockset = MCP_16MHz, const bool _initSPI = true); // init can
virtual byte init_Mask(byte num, byte ext, unsigned long ulData); // init Masks
virtual byte init_Filt(byte num, byte ext, unsigned long ulData); // init filters
virtual void setSleepWakeup(byte enable); // Enable or disable the wake up interrupt (If disabled the MCP2515 will not be woken up by CAN bus activity, making it send only)
@@ -92,10 +92,7 @@ public:
virtual byte trySendMsgBuf(unsigned long id, byte ext, byte rtrBit, byte len, const byte *buf, byte iTxBuf = 0xff); // as sendMsgBuf, but does not have any wait for free buffer
virtual byte sendMsgBuf(byte status, unsigned long id, byte ext, byte rtrBit, byte len, volatile const byte *buf); // send message buf by using parsed buffer status
virtual byte sendMsgBuf(unsigned long id, byte ext, byte rtrBit, byte len, const byte *buf, bool wait_sent = true); // send buf
/* wrapper */
inline byte sendMsgBuf(unsigned long id, byte ext, byte len, const byte *buf) {
return sendMsgBuf(id, ext, 0, len, buf, true);
}
using MCP_CAN::sendMsgBuf; // make other overloads visible
virtual void clearBufferTransmitIfFlags(byte flags = 0); // Clear transmit flags according to status
virtual byte readRxTxStatus(void); // read has something send or received
+8
View File
@@ -448,10 +448,18 @@
#define MCP_8MHz_100kBPS_CFG2 (0xb4)
#define MCP_8MHz_100kBPS_CFG3 (0x06)
#define MCP_8MHz_95k2BPS_CFG1 (0x01)
#define MCP_8MHz_95k2BPS_CFG2 (0xBB)
#define MCP_8MHz_95k2BPS_CFG3 (0x07)
#define MCP_8MHz_80kBPS_CFG1 (0x01)
#define MCP_8MHz_80kBPS_CFG2 (0xbf)
#define MCP_8MHz_80kBPS_CFG3 (0x07)
#define MCP_8MHz_83k3BPS_CFG1 (0x01)
#define MCP_8MHz_83k3BPS_CFG2 (0xBE)
#define MCP_8MHz_83k3BPS_CFG3 (0x07)
#define MCP_8MHz_50kBPS_CFG1 (0x03)
#define MCP_8MHz_50kBPS_CFG2 (0xb4)
#define MCP_8MHz_50kBPS_CFG3 (0x06)
+2 -2
View File
@@ -55,8 +55,8 @@ uint16_t DRV_CANFDSPI_CalculateCRC16(uint8_t *data, uint16_t size) {
** Function name: begin
** Descriptions: init can and set speed
*********************************************************************************************************/
byte mcp2518fd::begin(uint32_t speedset, const byte clockset) {
SPI.begin();
byte mcp2518fd::begin(uint32_t speedset, const byte clockset, const bool _initSPI) {
if (_initSPI) pSPI->begin();
/* compatible layer translation */
speedset = bittime_compat_to_mcp2518fd(speedset);
+4 -5
View File
@@ -112,7 +112,8 @@ public:
* or fill by CANFD::BITRATE()
*/
virtual byte begin(uint32_t speedset,
const byte clockset = MCP2518FD_40MHz); // init can
const byte clockset = MCP2518FD_40MHz,
const bool _initSPI = true); // init can
virtual byte init_Mask(byte num, byte ext, unsigned long ulData);
virtual byte init_Filt(byte num, byte ext,
unsigned long ulData); // init filters
@@ -154,10 +155,8 @@ public:
byte dlc, volatile const byte *buf);
virtual byte sendMsgBuf(unsigned long id, byte ext, byte rtr, byte dlc,
const byte *buf, bool wait_sent = true);
/* wrapper */
inline byte sendMsgBuf(unsigned long id, byte ext, byte len, const byte *buf) {
return sendMsgBuf(id, ext, 0, len, buf, true);
}
using MCP_CAN::sendMsgBuf; // make other overloads visible
virtual void clearBufferTransmitIfFlags(byte flags = 0);
virtual byte readRxTxStatus(void);
+20 -2
View File
@@ -5,6 +5,19 @@
#include <SPI.h>
#include <inttypes.h>
#ifndef SERIAL_PORT_MONITOR
#ifdef SEEED_XIAO_M0
#define SERIAL_PORT_MONITOR Serial
#elif defined(ARDUINO_SAMD_VARIANT_COMPLIANCE)
#define SERIAL_PORT_MONITOR SerialUSB
#else
#define SERIAL_PORT_MONITOR Serial
#endif
#endif
#define CAN_OK (0)
#define CAN_FAILINIT (1)
#define CAN_FAILTX (2)
@@ -41,6 +54,7 @@ typedef enum {
CAN_80KBPS ,
CAN_83K3BPS ,
CAN_95KBPS ,
CAN_95K2BPS ,
CAN_100KBPS ,
CAN_125KBPS ,
CAN_200KBPS ,
@@ -62,7 +76,7 @@ public:
* speedset be in MCP_BITTIME_SETUP
* clockset be in MCP_CLOCK_T
*/
virtual byte begin(uint32_t speedset, const byte clockset) = 0; // init can
virtual byte begin(uint32_t speedset, const byte clockset, const bool _initSPI = true) = 0; // init can
virtual byte init_Mask(byte num, byte ext, unsigned long ulData) = 0; // init Masks
virtual byte init_Filt(byte num, byte ext, unsigned long ulData) = 0; // init filters
virtual void setSleepWakeup(byte enable) = 0; // Enable or disable the wake up interrupt
@@ -94,7 +108,11 @@ public:
byte len, volatile const byte *buf) = 0; // send message buf by using parsed buffer status
virtual byte sendMsgBuf(unsigned long id, byte ext, byte rtrBit,
byte len, const byte *buf, bool wait_sent = true) = 0; // send message with wait
/* wrapper */
inline byte sendMsgBuf(unsigned long id, byte ext, byte len, const byte *buf) {
return sendMsgBuf(id, ext, 0, len, buf, true);
}
virtual void clearBufferTransmitIfFlags(byte flags = 0) = 0; // Clear transmit flags according to status
virtual byte readRxTxStatus(void) = 0; // read has something send or received
virtual byte checkClearRxStatus(byte *status) = 0; // read and clear and return first found rx status bit