{"id":2221,"date":"2023-12-31T04:50:44","date_gmt":"2023-12-31T04:50:44","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=2221"},"modified":"2024-01-03T04:00:20","modified_gmt":"2024-01-03T04:00:20","slug":"stm32-advanced-peripherals-canbus-part-2-canbus-initialization","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=2221","title":{"rendered":"STM32 Advanced Peripherals : CANBus Part 2: CANBus Initialization"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"440\" height=\"300\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/634d21bf24d32605e5020af5_CAN-bus-high-low-nodes-1.jpg\" alt=\"\" class=\"wp-image-2222\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/634d21bf24d32605e5020af5_CAN-bus-high-low-nodes-1.jpg 440w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/634d21bf24d32605e5020af5_CAN-bus-high-low-nodes-1-300x205.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/634d21bf24d32605e5020af5_CAN-bus-high-low-nodes-1-400x273.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/634d21bf24d32605e5020af5_CAN-bus-high-low-nodes-1-250x170.jpg 250w\" sizes=\"(max-width: 440px) 100vw, 440px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In part of the this guide series (<a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=2216\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=2216\" target=\"_blank\">here<\/a>), we took a look at CANBus and it features, CANBus peripheral of STM32F446 and its feature.<\/p>\n\n\n\n<p>In part two, we shall initialize the CANBus pins, CANBus and the filter to accept data with fixed identifier.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Required steps.<\/li><li>GPIO initialization and configuration.<\/li><li>CANBus initialization.<\/li><li>Filter Configuration.<\/li><li>CANBus start.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">8.Required Steps:<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Enable Clock:<\/strong><ul><li>Enable the clock for the CAN peripheral.<\/li><\/ul><\/li><li><strong>Initialization Mode:<\/strong><ul><li>Enter initialization mode for CAN configuration.<\/li><\/ul><\/li><li><strong>Bit Timing Configuration:<\/strong><ul><li>Configure the bit timing parameters (BTR register) based on the required baud rate and other settings.<\/li><\/ul><\/li><li><strong>Exit Initialization Mode:<\/strong><ul><li>Exit initialization mode to start normal CAN operation.<\/li><\/ul><\/li><li><strong>Enable Interrupts (Optional):<\/strong><ul><li>If you want to use interrupts, enable the relevant interrupt sources in the CAN interrupt enable register (IER) and configure NVIC.<\/li><\/ul><\/li><li><strong>Filter Configuration:<\/strong><ul><li>Enter filter initialization mode and configure CAN filter(s) (example values provided).<\/li><li>Exit filter initialization mode.<\/li><\/ul><\/li><li><strong>Main Loop:<\/strong><ul><li>Enter the main application loop.<\/li><\/ul><\/li><li><strong>Interrupt Handler (Optional):<\/strong><ul><li>If using interrupts, implement the interrupt handler to handle received messages.<\/li><\/ul><\/li><\/ol>\n\n\n\n<p>Later, we shall see if the interrupt is necessary or not.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">9. GPIO Initialization and Configuration:<\/h2>\n\n\n\n<p>From part 1, we shall use PB8 and PB9 for CANRX and CANTX respectively.<\/p>\n\n\n\n<p>We start by enabling clock access to GPIOB:<\/p>\n\n\n\n<p>Since the GPIOB is connected to AHB1 bus as shown in figure below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"731\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.04\u202fAM-1024x731.png\" alt=\"\" class=\"wp-image-2223\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.04\u202fAM-1024x731.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.04\u202fAM-300x214.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.04\u202fAM-768x548.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.04\u202fAM-1536x1097.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.04\u202fAM-2048x1462.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.04\u202fAM-1150x821.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.04\u202fAM-750x535.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.04\u202fAM-400x286.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.04\u202fAM-250x178.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>We can enable clock access to GPIOB by setting the corresponding bit in AHB1ENR register:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"420\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.44\u202fAM-1024x420.png\" alt=\"\" class=\"wp-image-2224\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.44\u202fAM-1024x420.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.44\u202fAM-300x123.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.44\u202fAM-768x315.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.44\u202fAM-1536x629.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.44\u202fAM-2048x839.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.44\u202fAM-1150x471.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.44\u202fAM-750x307.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.44\u202fAM-400x164.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.12.44\u202fAM-250x102.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Create new header file and source file with name of CANBus.h and CANBus.c respectively:<\/p>\n\n\n\n<p>Within the source file:<\/p>\n\n\n\n<p>Include the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;CANBus.h&quot;\n#include &quot;stm32f4xx.h&quot;<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Declare the following function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void CANBus_Pins_Init(void)<\/pre><\/div>\n\n\n\n<p>This function will initialize and configure the CANBus pins. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Enable clock access to GPIOB*\/\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOBEN;<\/pre><\/div>\n\n\n\n<p>Next, we shall set both PB8 and PB9 to alternate function as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"631\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.17.25\u202fAM-1024x631.png\" alt=\"\" class=\"wp-image-2225\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.17.25\u202fAM-1024x631.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.17.25\u202fAM-300x185.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.17.25\u202fAM-768x473.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.17.25\u202fAM-1536x947.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.17.25\u202fAM-2048x1262.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.17.25\u202fAM-1150x709.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.17.25\u202fAM-750x462.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.17.25\u202fAM-400x247.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.17.25\u202fAM-250x154.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\tGPIOB-&gt;MODER|=GPIO_MODER_MODE8_1|GPIO_MODER_MODE9_1;\n\tGPIOB-&gt;MODER&amp;=~(GPIO_MODER_MODE8_0|GPIO_MODER_MODE9_0);<\/pre><\/div>\n\n\n\n<p>Now, we need to find which AF responsible for CANBus:<\/p>\n\n\n\n<p>From the figure below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"789\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.19.11\u202fAM-789x1024.png\" alt=\"\" class=\"wp-image-2226\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.19.11\u202fAM-789x1024.png 789w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.19.11\u202fAM-231x300.png 231w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.19.11\u202fAM-768x997.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.19.11\u202fAM-1184x1536.png 1184w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.19.11\u202fAM-1150x1492.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.19.11\u202fAM-750x973.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.19.11\u202fAM-400x519.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.19.11\u202fAM-250x324.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.19.11\u202fAM.png 1512w\" sizes=\"(max-width: 789px) 100vw, 789px\" \/><\/figure>\n\n\n\n<p>The required function is AF09<\/p>\n\n\n\n<p>Create symbolic name as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#define CAN_AF 0x09<\/pre><\/div>\n\n\n\n<p>Configure the pin alternate function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">GPIOB-&gt;AFR[1]|=(CAN_AF&lt;&lt;GPIO_AFRH_AFSEL8_Pos)|(CAN_AF&lt;&lt;GPIO_AFRH_AFSEL9_Pos);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">10. CANBus Initialization:<\/h2>\n\n\n\n<p>Declare a new function as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void CANBus_Init(void)<\/pre><\/div>\n\n\n\n<p>This function will initialize the CANBus:<\/p>\n\n\n\n<p>We start off by enabling clock access to CANBus:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"794\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.28.12\u202fAM-794x1024.png\" alt=\"\" class=\"wp-image-2227\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.28.12\u202fAM-794x1024.png 794w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.28.12\u202fAM-232x300.png 232w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.28.12\u202fAM-768x991.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.28.12\u202fAM-1190x1536.png 1190w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.28.12\u202fAM-1150x1484.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.28.12\u202fAM-750x968.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.28.12\u202fAM-400x516.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.28.12\u202fAM-250x323.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.28.12\u202fAM.png 1274w\" sizes=\"(max-width: 794px) 100vw, 794px\" \/><\/figure>\n\n\n\n<p>Since the CANBus is connected to APB1, we can enable the clock access to it by setting the corresponding bit in APB1ENR to 1:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"972\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.29.47\u202fAM-972x1024.png\" alt=\"\" class=\"wp-image-2228\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.29.47\u202fAM-972x1024.png 972w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.29.47\u202fAM-285x300.png 285w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.29.47\u202fAM-768x809.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.29.47\u202fAM-1458x1536.png 1458w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.29.47\u202fAM-1150x1212.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.29.47\u202fAM-750x790.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.29.47\u202fAM-400x422.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.29.47\u202fAM-250x263.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.29.47\u202fAM.png 1562w\" sizes=\"(max-width: 972px) 100vw, 972px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Enable Clock access to CAN1*\/\n\tRCC-&gt;APB1ENR |= RCC_APB1ENR_CAN1EN;<\/pre><\/div>\n\n\n\n<p>In order to initialize the CANBus, we need to set it into initialization mode.<\/p>\n\n\n\n<p>We can do this by setting INRQ bit in MCR register to 1:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1009\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.31.56\u202fAM-1009x1024.png\" alt=\"\" class=\"wp-image-2229\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.31.56\u202fAM-1009x1024.png 1009w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.31.56\u202fAM-295x300.png 295w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.31.56\u202fAM-768x780.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.31.56\u202fAM-1513x1536.png 1513w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.31.56\u202fAM-1150x1168.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.31.56\u202fAM-750x762.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.31.56\u202fAM-400x406.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.31.56\u202fAM-250x254.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.31.56\u202fAM.png 1562w\" sizes=\"(max-width: 1009px) 100vw, 1009px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">    \/* Enter Initialization mode*\/\n    CAN1-&gt;MCR |= CAN_MCR_INRQ;\n    \/*Wait until CANBus peripheral is in initialization mdoe*\/\n    while (!(CAN1-&gt;MSR &amp; CAN_MSR_INAK));<\/pre><\/div>\n\n\n\n<p>Exit from sleep mode:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"900\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.43.34\u202fAM-1024x900.png\" alt=\"\" class=\"wp-image-2235\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.43.34\u202fAM-1024x900.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.43.34\u202fAM-300x264.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.43.34\u202fAM-768x675.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.43.34\u202fAM-1536x1349.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.43.34\u202fAM-2048x1799.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.43.34\u202fAM-1150x1010.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.43.34\u202fAM-750x659.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.43.34\u202fAM-400x351.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.43.34\u202fAM-250x220.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">    \/\/ Enable CAN1 peripheral\n    CAN1-&gt;MCR &amp;= ~CAN_MCR_SLEEP;\n    while ((CAN1-&gt;MSR &amp; CAN_MSR_SLAK)!=0U);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Next, we shall configure the timing:<\/p>\n\n\n\n<p>The parameters and results according to STM32CubeMX:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"264\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.39.37\u202fAM-1024x264.png\" alt=\"\" class=\"wp-image-2230\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.39.37\u202fAM-1024x264.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.39.37\u202fAM-300x77.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.39.37\u202fAM-768x198.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.39.37\u202fAM-1150x296.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.39.37\u202fAM-750x193.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.39.37\u202fAM-400x103.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.39.37\u202fAM-250x64.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.39.37\u202fAM.png 1242w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"895\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.40.50\u202fAM-895x1024.png\" alt=\"\" class=\"wp-image-2231\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.40.50\u202fAM-895x1024.png 895w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.40.50\u202fAM-262x300.png 262w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.40.50\u202fAM-768x879.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.40.50\u202fAM-1343x1536.png 1343w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.40.50\u202fAM-1150x1316.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.40.50\u202fAM-750x858.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.40.50\u202fAM-400x458.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.40.50\u202fAM-250x286.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.40.50\u202fAM.png 1680w\" sizes=\"(max-width: 895px) 100vw, 895px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">    \/*Configure the timing with the following parameters\n     * Normal mode.\n     * Loop back mode is disabled.\n     * Resynchronization jump width to 1 (value - 1).\n     * Prescale of 10. (value - 1)\n     * Time quanta segment 1 is 2 (value - 1)\n     * Time quanta segment 2 is 1 (value - 1)\n     * Baud is 400Kbps\n     * *\/\n\n    \/*Reset the non-zero initial values*\/\n    CAN1-&gt;BTR&amp;=~(CAN_BTR_TS1_Msk|CAN_BTR_TS2_Msk|CAN_BTR_SJW_Msk);\n\n    CAN1-&gt;BTR=(1&lt;&lt;CAN_BTR_TS1_Pos)|(0&lt;&lt;CAN_BTR_TS2_Pos)\n    \t\t|(9U&lt;&lt;CAN_BTR_BRP_Pos);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>The following parameters can be configured and set to disabled within this guide:<\/p>\n\n\n\n<p>Other basic parameters can be configured according your application<\/p>\n\n\n\n<p>* The following is the configuration:<\/p>\n\n\n\n<p>* Time triggered communication is disabled.<\/p>\n\n\n\n<p>* Automatic bus-off management is disabled.<\/p>\n\n\n\n<p>* Automatic wake-up is disabled.<\/p>\n\n\n\n<p>* Automatic retransmission is off.<\/p>\n\n\n\n<p>* Receive FIFO lock mode is disabled.<\/p>\n\n\n\n<p>* Transmit FIFO Priority is off<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">11. Filter Configuration:<\/h2>\n\n\n\n<p>We shall configure filter 18 and to accept data from identifier 0f 0x446:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void Filter_Configuration(void)\n{\n\t\/* Set the filter initialization mode*\/\n\tCAN1-&gt;FMR |= CAN_FMR_FINIT;\n\n\t\/*Set the slave Filter to start from 20*\/\n\tCAN1-&gt;FMR &amp;=~(CAN_FMR_CAN2SB_Msk);\n\tCAN1-&gt;FMR |=(20&lt;&lt;CAN_FMR_CAN2SB_Pos);\n\n\tCAN1-&gt;FA1R&amp;=~(CAN_FA1R_FACT18);\n\n    CAN1-&gt;FS1R |= CAN_FS1R_FSC18;  \/\/ Set to 1 for 32-bit scale configuration\n\n\n    CAN1-&gt;FM1R &amp;= ~CAN_FM1R_FBM18; \/\/ Set to 0 for identifier mask mode\n\n    CAN1-&gt;sFilterRegister[18].FR1 = (0x446&lt;&lt;5) &lt;&lt; 16; \/\/ Identifier\n\n    CAN1-&gt;sFilterRegister[18].FR2 = (0x446&lt;&lt;5) &lt;&lt; 16; \/\/ Identifier mask \n    \n    \/*Assign filter 18 to FIFO0*\/\n    CAN1-&gt;FFA1R&amp;=~CAN_FFA1R_FFA18;\n\n    \/\/ Activate filter 18\n    CAN1-&gt;FA1R |= CAN_FA1R_FACT18;\n\n\n    CAN1-&gt;FMR &amp;= ~CAN_FMR_FINIT; \/\/ Clear the filter initialization mode\n\n}<\/pre><\/div>\n\n\n\n<p>The steps as following:<\/p>\n\n\n\n<p>Set the filter mode to initialization mode:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"367\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.47.26\u202fAM-1024x367.png\" alt=\"\" class=\"wp-image-2236\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.47.26\u202fAM-1024x367.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.47.26\u202fAM-300x108.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.47.26\u202fAM-768x275.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.47.26\u202fAM-1536x551.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.47.26\u202fAM-2048x734.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.47.26\u202fAM-1150x412.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.47.26\u202fAM-750x269.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.47.26\u202fAM-400x143.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.47.26\u202fAM-250x90.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Since we are using filter 18 for this guide, we need to assign filter 20 to 27 for the slave CANBus (CAN2), this can be done using CANSB bits:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"367\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.49.59\u202fAM-1024x367.png\" alt=\"\" class=\"wp-image-2237\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.49.59\u202fAM-1024x367.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.49.59\u202fAM-300x108.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.49.59\u202fAM-768x275.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.49.59\u202fAM-1536x551.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.49.59\u202fAM-2048x734.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.49.59\u202fAM-1150x412.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.49.59\u202fAM-750x269.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.49.59\u202fAM-400x143.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.49.59\u202fAM-250x90.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Clear related bits.<\/li><li>Set the buts to be 20.<\/li><\/ul>\n\n\n\n<p>Deactivate filter 18:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"381\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.51.16\u202fAM-1024x381.png\" alt=\"\" class=\"wp-image-2238\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.51.16\u202fAM-1024x381.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.51.16\u202fAM-300x112.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.51.16\u202fAM-768x286.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.51.16\u202fAM-1536x571.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.51.16\u202fAM-2048x762.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.51.16\u202fAM-1150x428.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.51.16\u202fAM-750x279.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.51.16\u202fAM-400x149.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.51.16\u202fAM-250x93.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Set the scale to be single 32-bit:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"555\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.52.57\u202fAM-1024x555.png\" alt=\"\" class=\"wp-image-2239\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.52.57\u202fAM-1024x555.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.52.57\u202fAM-300x163.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.52.57\u202fAM-768x416.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.52.57\u202fAM-1536x832.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.52.57\u202fAM-2048x1110.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.52.57\u202fAM-1150x623.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.52.57\u202fAM-750x406.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.52.57\u202fAM-400x217.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.52.57\u202fAM-250x135.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Set the mode to be Mask mode:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"625\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.54.18\u202fAM-1024x625.png\" alt=\"\" class=\"wp-image-2240\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.54.18\u202fAM-1024x625.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.54.18\u202fAM-300x183.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.54.18\u202fAM-768x469.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.54.18\u202fAM-1536x937.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.54.18\u202fAM-2048x1250.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.54.18\u202fAM-1150x702.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.54.18\u202fAM-750x458.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.54.18\u202fAM-400x244.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.54.18\u202fAM-250x153.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Set the identifier and the mask to be 0x446<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"827\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.10\u202fAM-1024x827.png\" alt=\"\" class=\"wp-image-2241\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.10\u202fAM-1024x827.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.10\u202fAM-300x242.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.10\u202fAM-768x620.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.10\u202fAM-1536x1240.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.10\u202fAM-2048x1654.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.10\u202fAM-1150x929.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.10\u202fAM-750x606.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.10\u202fAM-400x323.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.10\u202fAM-250x202.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Assign filter 18 to FIFO0:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"562\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.51\u202fAM-1024x562.png\" alt=\"\" class=\"wp-image-2242\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.51\u202fAM-1024x562.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.51\u202fAM-300x165.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.51\u202fAM-768x422.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.51\u202fAM-1536x843.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.51\u202fAM-2048x1124.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.51\u202fAM-1150x631.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.51\u202fAM-750x412.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.51\u202fAM-400x220.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/01\/Screenshot-2024-01-03-at-6.57.51\u202fAM-250x137.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Finally, activate filter 18 and exit initialization mode.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">12. CANBus start:<\/h2>\n\n\n\n<p>To start the CANBus, we need the following steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Exit Initialization mode.<\/li><li>Wait until the initialization is exited.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"921\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.49.49\u202fAM-1024x921.png\" alt=\"\" class=\"wp-image-2232\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.49.49\u202fAM-1024x921.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.49.49\u202fAM-300x270.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.49.49\u202fAM-768x690.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.49.49\u202fAM-1536x1381.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.49.49\u202fAM-2048x1841.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.49.49\u202fAM-1150x1034.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.49.49\u202fAM-750x674.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.49.49\u202fAM-400x360.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/12\/Screenshot-2023-12-31-at-7.49.49\u202fAM-250x225.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void CANBus_Start(void)\n{\n    \/\/ Leave Initialization mode\n    CAN1-&gt;MCR &amp;= ~CAN_MCR_INRQ;\n    while (CAN1-&gt;MSR &amp; CAN_MSR_INAK);\n\n\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In part three, we shall transmit and receive data.<\/p>\n\n\n\n<p>Stay tuned.<\/p>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In part of the this guide series (here), we took a look at CANBus and it features, CANBus peripheral of STM32F446 and its feature. In part two, we shall initialize the CANBus pins, CANBus and the filter to accept data with fixed identifier. In this guide, we shall cover the following: Required steps. GPIO initialization [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-2221","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2221"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2221"}],"version-history":[{"count":3,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2221\/revisions"}],"predecessor-version":[{"id":2244,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2221\/revisions\/2244"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}