begin()
描述
初始化 CANBus 函式庫。
語法
CAN.begin()
CAN.begin(speed)
參數
speed
:CAN 的傳輸速度,可以設定以下 10 種速度其中之一。此參數是非必要的,如果沒有輸入此參數,預設的傳輸速度是 10KBPS。
- CAN_10KBPS
- CAN_20KBPS
- CAN_50KBPS
- CAN_83K3BPS
- CAN_100KBPS
- CAN_125KBPS
- CAN_250KBPS
- CAN_500KBPS
- CAN_833KBPS
- CAN_1000KBPS
回傳
無回傳值
範例
#include <CANBus.h> unsigned char buf[8] = {0, 1, 2, 3, 4, 5, 6, 7}; void setup() { Serial.begin(115200); CAN.begin(CAN_500KBPS); // 設定 CAN 的傳輸速度為 500KBPS } void loop() { CAN.beginTransmission(0x00, CAN_STDID); // 外部 CAN device 的 ID 為 0x00,使用標準資料幀 CAN.write(buf, 8); // 送出 8 bytes 資料 CAN.endTransmission(); // 結束傳送 delay(10); }
See also
- beginTransmission()
- write()
- endTransmission()
The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.