{"id":9452,"date":"2022-06-14T02:24:41","date_gmt":"2022-06-14T02:24:41","guid":{"rendered":"https:\/\/www.qec.tw\/?p=9452"},"modified":"2026-01-28T13:43:01","modified_gmt":"2026-01-28T05:43:01","slug":"can-init_filt","status":"publish","type":"post","link":"https:\/\/www.qec.tw\/zh\/86duino-library\/canbus\/can-init_filt\/","title":{"rendered":"CAN.init_Filt()"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">[CANBus]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Description<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<br>Combining with the\u00a0<a href=\"https:\/\/www.qec.tw\/86duino-library\/canbus\/can-init_mask\/\">init_Mask()<\/a>\u00a0function, receiving data can be limited to CAN ID within the A ~ B range.<br>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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>CAN.init_Filt(num, ext, ulData)<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Parameters<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>num: Identify filter ID to be used, within the 0 ~ 31 range.<\/li>\n\n\n\n<li>ext: data transmission format. There are 4 different options:\n<ul class=\"wp-block-list\">\n<li><code>CAN_STDID<\/code>: Standard data frame, comply with CAN 2.0A standard. ID range: 0 ~ 0x7FF<\/li>\n\n\n\n<li><code>CAN_EXTID<\/code>: Extended data frame, comply with CAN 2.0B standard. ID range: 0 ~ 0x1FFFFFFF<\/li>\n\n\n\n<li><code>CAN_STDID_REMOTE<\/code>: Standard remote frame, comply with CAN 2.0A standard. ID range: 0 ~ 0x7FF<\/li>\n\n\n\n<li><code>CAN_EXTID_REMOTE<\/code>: Extended remote frame, comply with CAN 2.0B standard. ID range: 0 ~ 0x1FFFFFFF<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>ulData: Filter value. Refer to the following example:<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>        Without mask:\n        0 0 0 0 0 0 1 1    Filter ID value: 0x03\n        0 0 0 0 0 0 0 0    Mask: 0x00\n        Range of CAN ID to receive data:: 0x03\n        With mask\n        0 0 0 1 1 0 0 1    Filter ID value: 0x19\n        0 0 0 0 0 0 0 1    Mask: 0x01\n        Range of CAN ID to receive data:0x18\u30010x19\n        0 1 0 1 1 1 0 0    Filter ID value: 0x5C\n        0 0 0 0 0 1 1 1    Mask: 0x07\n        Range of CAN ID to receive data:0x58 \uff5e 0x5F<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Returns<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>CAN_FAIL: Setting failed<\/li>\n\n\n\n<li>CAN_OK: Setting success<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Examples<\/h2>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &lt;CANBus.h&gt;\nunsigned char buf[8] = {0, 1, 2, 3, 4, 5, 6, 7};\n \nvoid setup() {\n    Serial.begin(115200);\n    CAN.begin(CAN_500KBPS); \/\/ Configure CAN bus transmission speed to 500KBPS\n    CAN.init_Filt(0, CAN_STDID, 0x019); \/\/ Configure filter ID 0 to 0x019, using Standard data frame\n    CAN.init_Mask(0, CAN_STDID, 0x01); \/\/ Configure mask for filter ID 0 to 0x01, using standard data frame\n}\n \nvoid loop() {\n    CAN.beginTransmission(0x00, CAN_STDID);    \/\/ Set external CAN ID to 0x00, using standard data frame\n    CAN.write(buf, 8);                         \/\/ Transmit 8 bytes of data\n    CAN.endTransmission();                     \/\/ End transmission\n    delay(10);\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">See also<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.qec.tw\/86duino-library\/canbus\/can-init_mask\/\">init_Mask<\/a>()<\/li>\n\n\n\n<li><a href=\"https:\/\/www.qec.tw\/86duino-library\/canbus\/can-begintransmission\/\">beginTransmission<\/a>()<\/li>\n\n\n\n<li><a href=\"https:\/\/www.qec.tw\/86duino-library\/canbus\/can-write\/\">write<\/a>()<\/li>\n\n\n\n<li><a href=\"https:\/\/www.qec.tw\/86duino-library\/canbus\/can-endtransmission\/\">endTransmission<\/a>()<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><a href=\"https:\/\/www.qec.tw\/86duino\/libraries\/\">Libraries Reference Home<\/a><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>The text of the 86Duino reference is a modification of&nbsp;<a href=\"http:\/\/arduino.cc\/en\/Reference\/HomePage\" target=\"_blank\" rel=\"noopener\">the Arduino reference<\/a>&nbsp;and is licensed under a&nbsp;<a href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/3.0\/\" target=\"_blank\" rel=\"noopener\">Creative Commons Attribution-ShareAlike 3.0 License<\/a>. Code samples in the reference are released into the public domain.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[CANBus] Description Function to filter CAN ID. On the 86Duino platform, there are 32 groups of CAN ID filters. When receiving data from the CAN [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9453,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[220],"tags":[162],"class_list":["post-9452","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-canbus","tag-86duino"],"_links":{"self":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts\/9452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/comments?post=9452"}],"version-history":[{"count":2,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts\/9452\/revisions"}],"predecessor-version":[{"id":17377,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/posts\/9452\/revisions\/17377"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/media\/9453"}],"wp:attachment":[{"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/media?parent=9452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/categories?post=9452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qec.tw\/zh\/wp-json\/wp\/v2\/tags?post=9452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}