Skip to content

Commit 188107f

Browse files
committed
Add write example
1 parent ed63a8f commit 188107f

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

examples/CAN_write/CAN_write.ino

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <SPI.h>
2+
#include <mcp2515.h>
3+
4+
struct can_frame canMsg1;
5+
struct can_frame canMsg2;
6+
MCP2515 mcp2515(10);
7+
8+
9+
void setup() {
10+
11+
canMsg1.can_id = 0x0F6;
12+
canMsg1.can_dlc = 8;
13+
canMsg1.data[0] = 0x8E;
14+
canMsg1.data[1] = 0x87;
15+
canMsg1.data[2] = 0x32;
16+
canMsg1.data[3] = 0xFA;
17+
canMsg1.data[4] = 0x26;
18+
canMsg1.data[5] = 0x8E;
19+
canMsg1.data[6] = 0xBE;
20+
canMsg1.data[7] = 0x86;
21+
22+
canMsg2.can_id = 0x036;
23+
canMsg2.can_dlc = 8;
24+
canMsg2.data[0] = 0x0E;
25+
canMsg2.data[1] = 0x00;
26+
canMsg2.data[2] = 0x00;
27+
canMsg2.data[3] = 0x08;
28+
canMsg2.data[4] = 0x01;
29+
canMsg2.data[5] = 0x00;
30+
canMsg2.data[6] = 0x00;
31+
canMsg2.data[7] = 0xA0;
32+
33+
while (!Serial);
34+
Serial.begin(115200);
35+
SPI.begin();
36+
37+
mcp2515.reset();
38+
mcp2515.setBitrate(CAN_125KBPS);
39+
mcp2515.setNormalMode();
40+
41+
Serial.println("Example: Write to CAN");
42+
}
43+
44+
void loop() {
45+
46+
mcp2515.sendMessage(&canMsg1);
47+
mcp2515.sendMessage(&canMsg2);
48+
49+
Serial.println("Messages sent");
50+
51+
delay(100);
52+
53+
}

0 commit comments

Comments
 (0)