source: rtos_arduino/trunk/arduino_lib/libraries/NcesCan/examples/send/send.ino@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 1.1 KB
Line 
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
7const int SPI_CS_PIN = 9;
8
9MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
10
11void setup()
12{
13 Serial.begin(115200);
14
15START_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
30unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
31void 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.