Line | |
---|
1 | // demo: set_mask_filter_send
|
---|
2 | // this demo will show you how to use mask and filter
|
---|
3 |
|
---|
4 | #include <mcp_can.h>
|
---|
5 | #include <SPI.h>
|
---|
6 |
|
---|
7 | // the cs pin of the version after v1.1 is default to D9
|
---|
8 | // v0.9b and v1.0 is default D10
|
---|
9 | const int SPI_CS_PIN = 9;
|
---|
10 |
|
---|
11 | MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
|
---|
12 |
|
---|
13 | void setup()
|
---|
14 | {
|
---|
15 | Serial.begin(115200);
|
---|
16 |
|
---|
17 | START_INIT:
|
---|
18 |
|
---|
19 | if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
|
---|
20 | {
|
---|
21 | Serial.println("CAN BUS Shield init ok!");
|
---|
22 | }
|
---|
23 | else
|
---|
24 | {
|
---|
25 | Serial.println("CAN BUS Shield init fail");
|
---|
26 | Serial.println("Init CAN BUS Shield again");
|
---|
27 | delay(100);
|
---|
28 | goto START_INIT;
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
|
---|
33 |
|
---|
34 | void loop()
|
---|
35 | {
|
---|
36 | for(int id=0; id<10; id++)
|
---|
37 | {
|
---|
38 | memset(stmp, id, sizeof(stmp)); // set id to send data buff
|
---|
39 | CAN.sendMsgBuf(id, 0, sizeof(stmp), stmp);
|
---|
40 | delay(100);
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | /*********************************************************************************************************
|
---|
45 | END FILE
|
---|
46 | *********************************************************************************************************/
|
---|
Note:
See
TracBrowser
for help on using the repository browser.