Skip to content

Instantly share code, notes, and snippets.

@bcdejp
Created December 20, 2015 10:49
Show Gist options
  • Save bcdejp/1ebd224efbac984342eb to your computer and use it in GitHub Desktop.
Save bcdejp/1ebd224efbac984342eb to your computer and use it in GitHub Desktop.
// CANの送信サンプル
//
// CAN信号を送信し続ける
// ライブラリヘッダのインクルード
#include <mcp_can.h>
#include <SPI.h>
#define CS_PIN (10) // CSを10ピンとする(変更可能)
MCP_CAN CAN0(CS_PIN);
void setup()
{
Serial.begin(115200);
if(CAN0.begin(CAN_500KBPS) == CAN_OK) Serial.print("can init ok!!\r\n");
else Serial.print("Can init fail!!\r\n");
}
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
// 送信データ: ID = 0x00, 標準フレーム, データ長=8
CAN0.sendMsgBuf(0x00, 0, 8, stmp);
delay(100); // send data per 100ms
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment