File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments