我想找...

搜尋

分享

目錄

CAN.init_Filt()

[CANBus]

描述

Function to filter CAN ID. On the 86Duino platform, there are 32 groups of CAN ID filters. When receiving data from the CAN bus, these filter ID can be used to determine whether the data need to be handled.
Combining with the init_Mask() function, receiving data can be limited to CAN ID within the A ~ B range.
When this function is used in a sketch without calling the init_Mask() or init)Filt() function first, data from all CAN ID will be accepted.

語法

CAN.init_Filt(num, ext, ulData)

參數

  • num: Identify filter ID to be used, within the 0 ~ 31 range.
    ext: data transmission format. There are 4 different options:
    • CAN_STDID: Standard data frame, comply with CAN 2.0A standard. ID range: 0 ~ 0x7FF
    • CAN_EXTID: Extended data frame, comply with CAN 2.0B standard. ID range: 0 ~ 0x1FFFFFFF
    • CAN_STDID_REMOTE: Standard remote frame, comply with CAN 2.0A standard. ID range: 0 ~ 0x7FF
    • CAN_EXTID_REMOTE: Extended remote frame, comply with CAN 2.0B standard. ID range: 0 ~ 0x1FFFFFFF
  • ulData: Filter value. Refer to the following example:
        Without mask:
        0 0 0 0 0 0 1 1    Filter ID value: 0x03
        0 0 0 0 0 0 0 0    Mask: 0x00
        Range of CAN ID to receive data:: 0x03
        With mask
        0 0 0 1 1 0 0 1    Filter ID value: 0x19
        0 0 0 0 0 0 0 1    Mask: 0x01
        Range of CAN ID to receive data:0x18、0x19
        0 1 0 1 1 1 0 0    Filter ID value: 0x5C
        0 0 0 0 0 1 1 1    Mask: 0x07
        Range of CAN ID to receive data:0x58 ~ 0x5F

回傳

  • CAN_FAIL: Setting failed
  • CAN_OK: Setting success

範例

#include <CANBus.h>
unsigned char buf[8] = {0, 1, 2, 3, 4, 5, 6, 7};
 
void setup() {
    Serial.begin(115200);
    CAN.begin(CAN_500KBPS); // Configure CAN bus transmission speed to 500KBPS
    CAN.init_Filt(0, CAN_STDID, 0x019); // Configure filter ID 0 to 0x019, using Standard data frame
    CAN.init_Mask(0, CAN_STDID, 0x01); // Configure mask for filter ID 0 to 0x01, using standard data frame
}
 
void loop() {
    CAN.beginTransmission(0x00, CAN_STDID);    // Set external CAN ID to 0x00, using standard data frame
    CAN.write(buf, 8);                         // Transmit 8 bytes of data
    CAN.endTransmission();                     // End transmission
    delay(10);
}

參考


函式庫參考主頁面

86Duino 參考的文本是根據 知識共享署名-相同方式分享 3.0 許可證,部分文本是從 Arduino 參考 修改的。 參考中的代碼示例已發佈到公共領域。

返回頂端