{"id":9448,"date":"2022-06-14T02:16:15","date_gmt":"2022-06-14T02:16:15","guid":{"rendered":"https:\/\/www.qec.tw\/?p=9448"},"modified":"2022-06-14T03:18:18","modified_gmt":"2022-06-14T03:18:18","slug":"can-init_mask","status":"publish","type":"post","link":"https:\/\/www.qec.tw\/ja\/86duino-library\/canbus\/can-init_mask\/","title":{"rendered":"CAN.init_Mask()"},"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\">On an 86Duino platform, there are 32 group of CAN ID mask. When there are data from external CAN device, the mask is used to determine the range of device ID (0 ~ N) which their data is to be handled. Combine with the&nbsp;<a href=\"https:\/\/www.qec.tw\/86duino-library\/canbus\/can-init_filt\/\">init_Filt()<\/a>&nbsp;function, this function can limit the range of CAN ID to be handled, within the A ~ B range. When the init_Mask() and ini_Filt() function are not called within a sketch, the CAN function library is set to accept data from all CAN ID.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>CAN.init_Mask(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\"><li>num: Mask ID, within the 0 ~ 31 range.<\/li><li>ext: One of the following 4 data transmission format.<ul><li>CAN_STDID: Standard data frame, comply with CAN 2.0A standard. ID range: 0 ~ 0x7FF<\/li><\/ul><ul><li>CAN_EXTID: Extended data frame, comply with CAN 2.0B standard. ID range: 0 ~ 0x1FFFFFFF<\/li><\/ul><ul><li>CAN_STDID_REMOTE: 3. CAN_STDID_REMOTE: Standard remote data frame, comply with CAN 2.0A standard. ID range: 0 ~ 0x7FF<\/li><\/ul><ul><li>CAN_EXTID_REMOTE: 4. CAN_EXTID_REMOTE: Extended remote data frame, comply with CAN 2.0B standard. ID range: 0 ~ 0x1FFFFFFF<\/li><\/ul><\/li><li>ulData: Mask value. Refer to the following examples:<\/li><\/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 0 0    Filter ID value: 0x00\n        0 0 0 0 0 0 1 1    Mask: 0x03\n\n        Range of CAN ID to receive data: 0x00 \uff5e 0x03\n\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\n        Range of CAN ID to receive data:0x18\u30010x19\n\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\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\"><li>CAN_FAIL: Setting failed<\/li><li>CAN_OK: Setting success<\/li><\/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\"><li><a href=\"https:\/\/www.qec.tw\/86duino-library\/canbus\/can-init_filt\/\">init_Filt<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-library\/canbus\/can-begintransmission\/\">beginTransmission<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-library\/canbus\/can-write\/\">write<\/a>()<\/li><li><a href=\"https:\/\/www.qec.tw\/86duino-library\/canbus\/can-endtransmission\/\">endTransmission<\/a>()<\/li><\/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 On an 86Duino platform, there are 32 group of CAN ID mask. When there are data from external CAN device, the mask is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9449,"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":"default","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-9448","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-canbus","tag-86duino"],"_links":{"self":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/9448","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/comments?post=9448"}],"version-history":[{"count":0,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/posts\/9448\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media\/9449"}],"wp:attachment":[{"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/media?parent=9448"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/categories?post=9448"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.qec.tw\/ja\/wp-json\/wp\/v2\/tags?post=9448"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}