mirror of
https://github.com/Seeed-Studio/Seeed_Arduino_CAN.git
synced 2026-07-27 19:55:59 +00:00
Add: a baudrate compatible argument to MCP2518FD CAN.begin()
This commit is contained in:
@@ -19,28 +19,32 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
@@ -82,11 +86,8 @@ void sendPid(unsigned char __pid) {
|
||||
void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
#include "mcp_can.h"
|
||||
#include "can-serial.h"
|
||||
|
||||
//#define CAN_2518FD
|
||||
// #define CAN_2518FD
|
||||
#define CAN_2515
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
#include "mcp2518fd_can.h"
|
||||
const int SPI_CS_PIN = BCM8;
|
||||
const int CAN_INT_PIN = BCM25;
|
||||
const int CAN_INT_PIN = BCM25;;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
@@ -30,8 +30,7 @@
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif // Set CS pin
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
@@ -7,19 +7,24 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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
|
||||
|
||||
#define SPI_CS_PIN 9
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
@@ -31,13 +36,8 @@ mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
|
||||
void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
#ifdef CAN_2515
|
||||
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) {
|
||||
#endif
|
||||
|
||||
SERIAL_PORT_MONITOR.println("CAN init failed, retry...");
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -7,19 +7,24 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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
|
||||
|
||||
#define SPI_CS_PIN 9
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
@@ -33,12 +38,7 @@ mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
#ifdef CAN_2515
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) {
|
||||
#endif // init can bus : baudrate = 500k
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
SERIAL_PORT_MONITOR.println("CAN init failed, retry");
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -7,31 +7,34 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif // Set CS pin
|
||||
#endif
|
||||
|
||||
const int LED = 8;
|
||||
boolean ledON = 1;
|
||||
@@ -40,11 +43,7 @@ void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
pinMode(LED, OUTPUT);
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -6,40 +6,39 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -7,31 +7,34 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif // Set CS pin
|
||||
#endif
|
||||
|
||||
|
||||
unsigned char flagRecv = 0;
|
||||
@@ -45,11 +48,7 @@ void setup() {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif // init can bus : baudrate = 500k
|
||||
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -9,42 +9,42 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#define MAX_DATA_SIZE 64
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#define MAX_DATA_SIZE 8
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while (!SERIAL_PORT_MONITOR) {}
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL_PORT_MONITOR.println(F("CAN init fail, retry..."));
|
||||
delay(100);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ void loop() {
|
||||
return;
|
||||
}
|
||||
|
||||
char prbuf[0x40];
|
||||
char prbuf[32 + MAX_DATA_SIZE * 3];
|
||||
int i, n;
|
||||
|
||||
unsigned long t = millis();
|
||||
|
||||
@@ -11,31 +11,34 @@ File myFile;
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif // Set CS pin
|
||||
#endif
|
||||
|
||||
unsigned char flagRecv = 0;
|
||||
unsigned char len = 0;
|
||||
@@ -45,11 +48,7 @@ char str[20];
|
||||
void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
|
||||
delay(100);
|
||||
}
|
||||
|
||||
+13
-14
@@ -7,41 +7,40 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif // Set CS pin
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -4,31 +4,34 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif // Set CS pin
|
||||
#endif
|
||||
|
||||
const int ledHIGH = 1;
|
||||
const int ledLOW = 0;
|
||||
@@ -37,11 +40,7 @@ const int ledLOW = 0;
|
||||
void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -9,43 +9,42 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#define MAX_DATA_SIZE 64
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
const int CAN_INT_PIN = 2;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#define MAX_DATA_SIZE 8
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
while(!SERIAL_PORT_MONITOR){}
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
|
||||
delay(100);
|
||||
}
|
||||
@@ -86,7 +85,8 @@ void loop() {
|
||||
CAN.sendMsgBuf(id, bool(type & 0x1),
|
||||
bool(type & 0x2),
|
||||
len, cdata);
|
||||
char prbuf[0x40];
|
||||
|
||||
char prbuf[32 + MAX_DATA_SIZE * 3];
|
||||
int n;
|
||||
|
||||
/* Displayed type:
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// demo: CAN Sleep Example - send
|
||||
// *** only works on AVR + MCP2515 platform
|
||||
//
|
||||
// by Kai, based on the send example by loovee and the additions from Zak Kemble (https://github.com/coryjfowler/MCP_CAN_lib/pull/10/files)
|
||||
//
|
||||
// See receive_sleep example for additional notes.
|
||||
|
||||
@@ -8,31 +8,35 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
const byte interruptPin = 2;
|
||||
unsigned char flagRecv = 0;
|
||||
unsigned char len = 0;
|
||||
unsigned char buf[8];
|
||||
@@ -41,12 +45,8 @@ char str[20];
|
||||
void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
attachInterrupt(digitalPinToInterrupt(interruptPin), MCP2515_ISR, FALLING); // start interrupt
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), MCP2515_ISR, FALLING); // start interrupt
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
|
||||
delay(100);
|
||||
}
|
||||
@@ -69,7 +69,6 @@ void setup() {
|
||||
CAN.init_Filt(3, 0, 0x07); // there are 6 filter in mcp2515
|
||||
CAN.init_Filt(4, 0, 0x08); // there are 6 filter in mcp2515
|
||||
CAN.init_Filt(5, 0, 0x09); // there are 6 filter in mcp2515
|
||||
|
||||
}
|
||||
|
||||
void MCP2515_ISR() {
|
||||
@@ -91,7 +90,6 @@ void loop() {
|
||||
SERIAL_PORT_MONITOR.print("\t");
|
||||
}
|
||||
SERIAL_PORT_MONITOR.println();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,27 +5,32 @@
|
||||
#define CAN_2515
|
||||
// #define CAN_2518FD
|
||||
|
||||
// the cs pin of the version after v1.1 is default to D9
|
||||
// v0.9b and v1.0 is default D10
|
||||
|
||||
// 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:
|
||||
// SPI_CS Pin: D9
|
||||
// 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"
|
||||
const int SPI_CS_PIN = 9;
|
||||
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
#ifdef CAN_2515
|
||||
#include "mcp2515_can.h"
|
||||
const int SPI_CS_PIN = 9;
|
||||
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
|
||||
#endif
|
||||
|
||||
@@ -34,11 +39,7 @@ void setup() {
|
||||
SERIAL_PORT_MONITOR.begin(115200);
|
||||
while(!Serial){};
|
||||
|
||||
#ifdef CAN_2518FD
|
||||
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
|
||||
#else
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
|
||||
#endif
|
||||
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -1607,6 +1607,32 @@ static const uint32_t canFilterObjectResetValues[] = {0x00000000, 0x00000000};
|
||||
static const uint32_t mcp25xxfdControlResetValues[] = {
|
||||
0x00000460, 0x00000003, 0x00000000, 0x00000000, 0x00000000};
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// compatible layer for MCP2515
|
||||
typedef enum {
|
||||
CAN_NOBPS,
|
||||
CAN_5KBPS,
|
||||
CAN_10KBPS,
|
||||
CAN_20KBPS,
|
||||
CAN_25KBPS,
|
||||
CAN_31K25BPS,
|
||||
CAN_33KBPS ,
|
||||
CAN_40KBPS ,
|
||||
CAN_50KBPS ,
|
||||
CAN_80KBPS ,
|
||||
CAN_83K3BPS ,
|
||||
CAN_95KBPS ,
|
||||
CAN_100KBPS ,
|
||||
CAN_125KBPS = CAN_125K_500K,
|
||||
CAN_200KBPS ,
|
||||
CAN_250KBPS = CAN_250K_500K,
|
||||
CAN_500KBPS = CAN_500K_1M,
|
||||
CAN_666KBPS ,
|
||||
CAN_1000KBPS = CAN_1000K_4M,
|
||||
} MCP2515_BITTIME_SETUP;
|
||||
|
||||
#ifdef __cplusplus // Provide C++ Compatibility
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user