begin()

描述

初始化 CANBus 函式库。

语法


CAN.begin()
CAN.begin(speed)

参数

speed:CAN 的传输速度,可以设定以下 10 种速度其中之一。此参数是非必要的,如果没有输入此参数,预设的传输速度是 10KBPS。

  1. CAN_10KBPS
  2. CAN_20KBPS
  3. CAN_50KBPS
  4. CAN_83K3BPS
  5. CAN_100KBPS
  6. CAN_125KBPS
  7. CAN_250KBPS
  8. CAN_500KBPS
  9. CAN_833KBPS
  10. 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.