Skip to content

Commit 41b9007

Browse files
wangcoolcPillar1989
authored andcommitted
Modified canbus send Blink example
1 parent 2ef6a99 commit 41b9007

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

examples/send_Blink/send_Blink.ino

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// demo: CAN-BUS Shield, send data
2-
#include <mcp_can.h>
32
#include <SPI.h>
43

54
/*SAMD core*/
@@ -9,18 +8,37 @@
98
#define SERIAL Serial
109
#endif
1110

11+
//#define CAN_2515
12+
#define CAN_2518FD
1213
// the cs pin of the version after v1.1 is default to D9
1314
// v0.9b and v1.0 is default D10
15+
16+
#ifdef CAN_2518FD
17+
#include "mcp2518fd_can.h"
18+
const int SPI_CS_PIN = BCM8;
19+
const int CAN_INT_PIN = BCM25;
20+
mcp2518fd CAN(SPI_CS_PIN); // Set CS pin
21+
#endif
22+
23+
#ifdef CAN_2515
24+
#include "mcp2515_can.h"
1425
const int SPI_CS_PIN = 9;
26+
const int CAN_INT_PIN = 2;
27+
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
28+
#endif // Set CS pin
29+
1530
const int ledHIGH = 1;
1631
const int ledLOW = 0;
17-
18-
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
32+
1933

2034
void setup() {
2135
SERIAL.begin(115200);
2236

23-
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
37+
#ifdef CAN_2518FD
38+
while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k
39+
#else
40+
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
41+
#endif
2442
SERIAL.println("CAN BUS Shield init fail");
2543
SERIAL.println(" Init CAN BUS Shield again");
2644
delay(100);

0 commit comments

Comments
 (0)