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