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 | const int ledHIGH = 1;
|
---|
| 9 | const int ledLOW = 0;
|
---|
| 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] = {ledHIGH, 1, 2, 3, ledLOW, 5, 6, 7};
|
---|
| 33 |
|
---|
| 34 | void loop()
|
---|
| 35 | { Serial.println("In loop");
|
---|
| 36 | // send data: id = 0x00, standrad frame, data len = 8, stmp: data buf
|
---|
| 37 | CAN.sendMsgBuf(0x70,0, 8, stmp);
|
---|
| 38 | delay(1000); // send data per 100ms
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | /*********************************************************************************************************
|
---|
| 42 | END FILE
|
---|
| 43 | *********************************************************************************************************/
|
---|
Note:
See
TracBrowser
for help on using the repository browser.