mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-07-28 04:06:45 +00:00
Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34c1d6ff91 | ||
|
|
ca8fcc7fe3 | ||
|
|
31438c426b | ||
|
|
ad48756e56 | ||
|
|
c8556d5c1b | ||
|
|
23b23eff5c | ||
|
|
6f556e2ac8 | ||
|
|
491283753f | ||
|
|
23666a81df | ||
|
|
6dcfabc65e | ||
|
|
02d18fb3b3 | ||
|
|
7328966ef0 | ||
|
|
adceb9b415 | ||
|
|
eb6887ba3c | ||
|
|
b946ae7c24 | ||
|
|
58a38c9387 | ||
|
|
e2cbc7bb07 | ||
|
|
06e6e163a9 | ||
|
|
9226a0ae6b | ||
|
|
6acaf5a258 | ||
|
|
b517530d07 | ||
|
|
c991cacd9a | ||
|
|
5a41853758 | ||
|
|
4080671c63 | ||
|
|
c110bf10c0 | ||
|
|
1351334686 | ||
|
|
f579f66402 | ||
|
|
1b63d26adc | ||
|
|
e9adda5cea | ||
|
|
bb92e93e9b |
@@ -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 }}
|
||||
@@ -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 }}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
*********************************************************************************************************/
|
||||
@@ -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
@@ -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": "1.20",
|
||||
"version": "2.3.3",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
name=CAN-BUS Shield
|
||||
version=2.3.0
|
||||
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
@@ -211,7 +211,7 @@ private:
|
||||
INT8U openCanBus();
|
||||
|
||||
INT8U sendMsgBuf(INT32U id, INT8U ext, INT8U rtr, INT8U len, INT8U *buf);
|
||||
|
||||
|
||||
void parseCanStdId();
|
||||
void parseCanExtId();
|
||||
};
|
||||
|
||||
+119
-3
@@ -533,6 +533,109 @@ byte mcp2515_can::mcp2515_configRate(const byte canSpeed, const byte clock) {
|
||||
}
|
||||
break;
|
||||
|
||||
case (MCP_12MHz) :
|
||||
switch (canSpeed) {
|
||||
case (CAN_20KBPS) :
|
||||
cfg1 = MCP_12MHz_20kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_20kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_20kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_25KBPS) :
|
||||
cfg1 = MCP_12MHz_25kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_25kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_25kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_31K25BPS) :
|
||||
cfg1 = MCP_12MHz_31k25BPS_CFG1;
|
||||
cfg2 = MCP_12MHz_31k25BPS_CFG2;
|
||||
cfg3 = MCP_12MHz_31k25BPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_33KBPS) :
|
||||
cfg1 = MCP_12MHz_33kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_33kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_33kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_40KBPS) :
|
||||
cfg1 = MCP_12MHz_40kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_40kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_40kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_50KBPS) :
|
||||
cfg1 = MCP_12MHz_50kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_50kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_50kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_80KBPS) :
|
||||
cfg1 = MCP_12MHz_80kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_80kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_80kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_83K3BPS) :
|
||||
cfg1 = MCP_12MHz_83k3BPS_CFG1;
|
||||
cfg2 = MCP_12MHz_83k3BPS_CFG2;
|
||||
cfg3 = MCP_12MHz_83k3BPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_95KBPS) :
|
||||
cfg1 = MCP_12MHz_95kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_95kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_95kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_100KBPS) :
|
||||
cfg1 = MCP_12MHz_100kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_100kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_100kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_125KBPS) :
|
||||
cfg1 = MCP_12MHz_125kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_125kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_125kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_200KBPS) :
|
||||
cfg1 = MCP_12MHz_200kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_200kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_200kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_250KBPS) :
|
||||
cfg1 = MCP_12MHz_250kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_250kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_250kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_500KBPS) :
|
||||
cfg1 = MCP_12MHz_500kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_500kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_500kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_666KBPS) :
|
||||
cfg1 = MCP_12MHz_666kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_666kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_666kBPS_CFG3;
|
||||
break;
|
||||
|
||||
case (CAN_1000KBPS) :
|
||||
cfg1 = MCP_12MHz_1000kBPS_CFG1;
|
||||
cfg2 = MCP_12MHz_1000kBPS_CFG2;
|
||||
cfg3 = MCP_12MHz_1000kBPS_CFG3;
|
||||
break;
|
||||
|
||||
default:
|
||||
set = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case (MCP_8MHz) :
|
||||
switch (canSpeed) {
|
||||
case (CAN_5KBPS) :
|
||||
@@ -577,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;
|
||||
@@ -929,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);
|
||||
@@ -943,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);
|
||||
@@ -1293,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
@@ -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
|
||||
|
||||
@@ -350,6 +350,73 @@
|
||||
#define MCP_16MHz_5kBPS_CFG3 (0x87)
|
||||
|
||||
|
||||
// speed 12M
|
||||
|
||||
#define MCP_12MHz_1000kBPS_CFG1 (0x00)//
|
||||
#define MCP_12MHz_1000kBPS_CFG2 (0x88)//
|
||||
#define MCP_12MHz_1000kBPS_CFG3 (0x01)//
|
||||
|
||||
#define MCP_12MHz_666kBPS_CFG1 (0x00)//
|
||||
#define MCP_12MHz_666kBPS_CFG2 (0x92)//
|
||||
#define MCP_12MHz_666kBPS_CFG3 (0x01)//
|
||||
|
||||
#define MCP_12MHz_500kBPS_CFG1 (0x00)
|
||||
#define MCP_12MHz_500kBPS_CFG2 (0x9B)
|
||||
#define MCP_12MHz_500kBPS_CFG3 (0x02)
|
||||
|
||||
#define MCP_12MHz_250kBPS_CFG1 (0x00)//
|
||||
#define MCP_12MHz_250kBPS_CFG2 (0xBF)//
|
||||
#define MCP_12MHz_250kBPS_CFG3 (0x06)///
|
||||
|
||||
#define MCP_12MHz_200kBPS_CFG1 (0x01)//
|
||||
#define MCP_12MHz_200kBPS_CFG2 (0xA4)//
|
||||
#define MCP_12MHz_200kBPS_CFG3 (0x03)//
|
||||
|
||||
#define MCP_12MHz_125kBPS_CFG1 (0x01)//
|
||||
#define MCP_12MHz_125kBPS_CFG2 (0xBF)//
|
||||
#define MCP_12MHz_125kBPS_CFG3 (0x06)//
|
||||
|
||||
#define MCP_12MHz_100kBPS_CFG1 (0x02)//
|
||||
#define MCP_12MHz_100kBPS_CFG2 (0xB6)//
|
||||
#define MCP_12MHz_100kBPS_CFG3 (0x04)//
|
||||
|
||||
#define MCP_12MHz_95kBPS_CFG1 (0x02)//
|
||||
#define MCP_12MHz_95kBPS_CFG2 (0xBE)//
|
||||
#define MCP_12MHz_95kBPS_CFG3 (0x04)//
|
||||
|
||||
#define MCP_12MHz_83k3BPS_CFG1 (0x03)//
|
||||
#define MCP_12MHz_83k3BPS_CFG2 (0xB5)//
|
||||
#define MCP_12MHz_83k3BPS_CFG3 (0x03)//
|
||||
|
||||
#define MCP_12MHz_80kBPS_CFG1 (0x04)//
|
||||
#define MCP_12MHz_80kBPS_CFG2 (0xA4)//
|
||||
#define MCP_12MHz_80kBPS_CFG3 (0x03)//
|
||||
|
||||
#define MCP_12MHz_50kBPS_CFG1 (0x05)//
|
||||
#define MCP_12MHz_50kBPS_CFG2 (0xB6)//
|
||||
#define MCP_12MHz_50kBPS_CFG3 (0x04)//
|
||||
|
||||
#define MCP_12MHz_40kBPS_CFG1 (0x09)//
|
||||
#define MCP_12MHz_40kBPS_CFG2 (0xA4)//
|
||||
#define MCP_12MHz_40kBPS_CFG3 (0x03)//
|
||||
|
||||
#define MCP_12MHz_33kBPS_CFG1 (0x0C)//
|
||||
#define MCP_12MHz_33kBPS_CFG2 (0xA4)//
|
||||
#define MCP_12MHz_33kBPS_CFG3 (0x02)//
|
||||
|
||||
#define MCP_12MHz_31k25BPS_CFG1 (0x0B)//
|
||||
#define MCP_12MHz_31k25BPS_CFG2 (0xAC)//
|
||||
#define MCP_12MHz_31k25BPS_CFG3 (0x03)//
|
||||
|
||||
#define MCP_12MHz_25kBPS_CFG1 (0X0B)//
|
||||
#define MCP_12MHz_25kBPS_CFG2 (0XB6)//
|
||||
#define MCP_12MHz_25kBPS_CFG3 (0X04)//
|
||||
|
||||
#define MCP_12MHz_20kBPS_CFG1 (0x0C)//
|
||||
#define MCP_12MHz_20kBPS_CFG2 (0xBF)//
|
||||
#define MCP_12MHz_20kBPS_CFG3 (0x05)//
|
||||
|
||||
|
||||
|
||||
// speed 8M
|
||||
|
||||
@@ -381,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)
|
||||
|
||||
+11
-11
@@ -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);
|
||||
@@ -1909,15 +1909,15 @@ byte mcp2518fd::init_Mask(byte num, byte ext, unsigned long ulData) {
|
||||
mcp2518fd_OperationModeSelect(CAN_CONFIGURATION_MODE);
|
||||
|
||||
mcp2518fd_FilterToFifoLink((CAN_FILTER)num, APP_RX_FIFO, false);
|
||||
|
||||
|
||||
// Setup RX Mask
|
||||
mObj.word = 0;
|
||||
mObj.bF.MSID = ulData;
|
||||
mObj.bF.MIDE = ext;
|
||||
err = mcp2518fd_FilterMaskConfigure((CAN_FILTER)num, &mObj.bF);
|
||||
|
||||
|
||||
mcp2518fd_FilterToFifoLink((CAN_FILTER)num, APP_RX_FIFO, true);
|
||||
|
||||
|
||||
mcp2518fd_OperationModeSelect(mcpMode);
|
||||
|
||||
return err;
|
||||
@@ -1932,7 +1932,7 @@ byte mcp2518fd::init_Filt(byte num, byte ext, unsigned long ulData) {
|
||||
err = mcp2518fd_OperationModeSelect(CAN_CONFIGURATION_MODE);
|
||||
|
||||
mcp2518fd_FilterToFifoLink((CAN_FILTER)num, APP_RX_FIFO, false);
|
||||
|
||||
|
||||
// Setup RX Filter
|
||||
fObj.word = 0;
|
||||
if (!ext) { // standard identifier
|
||||
@@ -1942,9 +1942,9 @@ byte mcp2518fd::init_Filt(byte num, byte ext, unsigned long ulData) {
|
||||
}
|
||||
fObj.bF.EXIDE = !!ext;
|
||||
mcp2518fd_FilterObjectConfigure((CAN_FILTER)num, &fObj.bF);
|
||||
|
||||
|
||||
mcp2518fd_FilterToFifoLink((CAN_FILTER)num, APP_RX_FIFO, true);
|
||||
|
||||
|
||||
mcp2518fd_OperationModeSelect(mcpMode);
|
||||
return err;
|
||||
}
|
||||
@@ -2066,7 +2066,7 @@ byte mcp2518fd::checkError(uint8_t* err_ptr) {
|
||||
byte mcp2518fd::mcp2518fd_readMsgBufID(volatile byte *len, volatile byte *buf) {
|
||||
mcp2518fd_ReceiveMessageGet(APP_RX_FIFO, &rxObj, rxd, MAX_DATA_BYTES);
|
||||
ext_flg = rxObj.bF.ctrl.IDE;
|
||||
can_id = ext_flg? (rxObj.bF.id.EID | (rxObj.bF.id.SID << 18))
|
||||
can_id = ext_flg? (rxObj.bF.id.EID | ((uint32_t) rxObj.bF.id.SID << 18))
|
||||
: rxObj.bF.id.SID;
|
||||
rtr = rxObj.bF.ctrl.RTR;
|
||||
uint8_t n = DRV_CANFDSPI_DlcToDataBytes((CAN_DLC)rxObj.bF.ctrl.DLC);
|
||||
@@ -2252,10 +2252,10 @@ byte mcp2518fd::mcpDigitalRead(const byte pin) {
|
||||
// Update data
|
||||
switch (pin) {
|
||||
case GPIO_PIN_0:
|
||||
state = (GPIO_PIN_STATE)iocon.bF.GPIO0;
|
||||
state = (GPIO_PIN_STATE)iocon.bF.GPIO0_;
|
||||
break;
|
||||
case GPIO_PIN_1:
|
||||
state = (GPIO_PIN_STATE)iocon.bF.GPIO1;
|
||||
state = (GPIO_PIN_STATE)iocon.bF.GPIO1_;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
|
||||
+4
-5
@@ -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);
|
||||
|
||||
@@ -1463,8 +1463,8 @@ typedef union _REG_IOCON {
|
||||
uint32_t LAT1 : 1;
|
||||
uint32_t unimplemented3 : 5;
|
||||
uint32_t HVDETSEL : 1;
|
||||
uint32_t GPIO0 : 1;
|
||||
uint32_t GPIO1 : 1;
|
||||
uint32_t GPIO0_ : 1;
|
||||
uint32_t GPIO1_ : 1;
|
||||
uint32_t unimplemented4 : 6;
|
||||
uint32_t PinMode0 : 1;
|
||||
uint32_t PinMode1 : 1;
|
||||
|
||||
+21
-2
@@ -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)
|
||||
@@ -20,6 +33,7 @@ typedef enum {
|
||||
MCP_NO_MHz,
|
||||
/* apply to MCP2515 */
|
||||
MCP_16MHz,
|
||||
MCP_12MHz,
|
||||
MCP_8MHz,
|
||||
/* apply to MCP2518FD */
|
||||
MCP2518FD_40MHz = MCP_16MHz /* To compatible MCP2515 shield */,
|
||||
@@ -40,6 +54,7 @@ typedef enum {
|
||||
CAN_80KBPS ,
|
||||
CAN_83K3BPS ,
|
||||
CAN_95KBPS ,
|
||||
CAN_95K2BPS ,
|
||||
CAN_100KBPS ,
|
||||
CAN_125KBPS ,
|
||||
CAN_200KBPS ,
|
||||
@@ -61,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
|
||||
@@ -93,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
|
||||
|
||||
Reference in New Issue
Block a user