{"id":292,"date":"2021-10-28T14:16:39","date_gmt":"2021-10-28T06:16:39","guid":{"rendered":"https:\/\/www.houjianwei.space\/?p=292"},"modified":"2022-09-13T10:08:54","modified_gmt":"2022-09-13T02:08:54","slug":"stm32%e7%b3%bb%e5%88%97%e6%96%87%e7%ab%a01stm32cubemx%e9%85%8d%e7%bd%aecan%e6%80%bb%e7%ba%bf%e9%80%9a%e4%bf%a1","status":"publish","type":"post","link":"https:\/\/jianwei.fun\/?p=292","title":{"rendered":"STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1"},"content":{"rendered":"\n<p class=\"has-vivid-cyan-blue-color has-text-color has-medium-font-size\">STM32CubeMX \u914d\u7f6e<\/p>\n\n\n\n<p>\u9996\u5148\u6253\u5f00STM32CubeMX \u9009\u62e9\u82af\u7247\u578b\u53f7\u5efa\u7acb\u5de5\u7a0b\uff0c\u6211\u8fd9\u91cc\u9009\u62e9STM32F03ZET6(\u6b63\u70b9\u539f\u5b50\u6218\u8230V3) \u5177\u4f53\u65b0\u5efa\u5de5\u7a0b\u7684\u8fc7\u7a0b\u4e0d\u518d\u8d58\u8ff0\uff0c\u592a\u57fa\u7840\u3002<br>\u9996\u5148\u914d\u7f6eSystem Core\u76ee\u5f55\u4e0b\u7684SYS\u548cRCC\u9009\u9879\u5361\u5982\u4e0b\u56fe\uff1a<br>\uff081\uff09\u914d\u7f6eSYS\u4e0b\u7684Debug\u4e3aSerial Wire<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/sys.png\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"576\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/sys-1024x576.png\" alt=\"\" class=\"wp-image-295\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/sys-1024x576.png 1024w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/sys-300x169.png 300w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/sys-768x432.png 768w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/sys-1536x864.png 1536w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/sys-1568x882.png 1568w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/sys.png 1920w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>\uff082\uff09\u914d\u7f6eRCC\u4e0b\u7684HSE\uff08\u9ad8\u901f\u65f6\u949f\uff09\u4e3a\u5916\u90e8\u6676\u632fCrystal\/Ceramic Resonator\uff0c\u5177\u4f53\u6839\u636e\u677f\u5b50\u7684\u786c\u4ef6\u914d\u7f6e\u8bbe\u7f6e<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/rcc.png\"><img decoding=\"async\" loading=\"lazy\" width=\"1002\" height=\"963\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/rcc.png\" alt=\"\" class=\"wp-image-297\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/rcc.png 1002w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/rcc-300x288.png 300w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/rcc-768x738.png 768w\" sizes=\"(max-width: 1002px) 100vw, 1002px\" \/><\/a><\/figure>\n\n\n\n<p>\uff083\uff09\u4f7f\u80fdCAN\u603b\u7ebf\u5e76\u914d\u7f6e\u76f8\u5173\u53c2\u6570<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/can.png\"><img decoding=\"async\" loading=\"lazy\" width=\"1000\" height=\"749\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/can.png\" alt=\"\" class=\"wp-image-299\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/can.png 1000w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/can-300x225.png 300w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/can-768x575.png 768w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/a><\/figure>\n\n\n\n<p>\u5728\u6b64\u8bf4\u660eCAN\u603b\u7ebf\u76f8\u5173\u53c2\u6570\u7684\u914d\u7f6e\u65b9\u6cd5\uff0c\u5728F103ZET6\u4e2dCAN\u662f\u6302\u8f7d\u5728APB1\u4e0b\u7684\u4f4e\u901f\u5916\u8bbe\uff0c\u65f6\u949f36MHz\uff0c\u53c2\u6570\u4e2d\u7684Prescaler(for Time Quantum)\u662f\u6307\u9884\u5206\u9891\u7cfb\u6570\uff0c\u8ddfCAN\u603b\u7ebf\u7684\u6ce2\u7279\u7387\u76f8\u5173\uff0c\u6211\u8fd9\u91cc\u8bbe\u7f6e\u4e3a36\u5206\u9891\uff0c\u5982\u6b64\u4e00\u6765\u65f6\u949f\u5c31\u662f1MHz,\u6bcf\u4e00\u4e2a\u5468\u671f\u4e3a1us\uff08\u5373\u540e\u9762\u53c2\u6570\u76841\u4e2aTime\u662f1us\uff09\u65b9\u4fbf\u8ba1\u7b97\uff0cTime Quanta in Bit Segment 1\u548cTime Quanta in Bit Segment 2 \u4e5f\u662f\u5f71\u54cd\u6ce2\u7279\u7387\u7684\u4e24\u4e2a\u53c2\u6570\uff0c\u5177\u4f53\u8ba1\u7b97\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>Bound=1\/(1*Tq+Tqbs1+Tqbs2)<\/p>\n\n\n\n<p>\u5176\u4e2dTqbs1\u4ee3\u8868\u7684\u5c31\u662fTime Quanta in Bit Segment 1\u6240\u5bf9\u5e94\u7684\u65f6\u95f4\uff0cTqbs2\u4ee3\u8868\u7684\u5c31\u662fTime Quanta in Bit Segment 2\u6240\u5bf9\u5e94\u7684\u65f6\u95f4,Tq\u4ee3\u8868\u7684\u662f1\u4e2aTime\u7684\u65f6\u95f4\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u4ee5\u6211\u7684\u914d\u7f6e\u4e3e\u4f8b\uff1a1\/\uff081us+4us+5us\uff09=100K\uff0c\u8fd9\u5c31\u662f\u6211\u7684\u6ce2\u7279\u7387\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u987a\u5e26\u63d0\u4e00\u4e0b\u56e0\u4e3a\u6211\u53ea\u6709\u4e00\u5757\u6218\u8230V3\uff0cMIni\u677f\u4e0a\u7684CAN\u6ca1\u6709\u5f15\u51fa\uff0c\u6240\u4ee5\u6211\u8bbe\u7f6eAdvenced Parameter\u4e0b\u7684Operating Mode \u4e3aLoopback\uff0c\u5373\u56de\u73af\u6a21\u5f0f\uff08\u81ea\u53d1\u81ea\u6536\uff09\u3002\u8bb0\u5f97\u6253\u5f00NVIC setting\u4e2d\u7684\u63a5\u6536\u4e2d\u65ad\uff0c\u4e0d\u7136\u662f\u6ca1\u6cd5\u63a5\u6536\u6570\u636e\u7684<br><\/p>\n\n\n\n<p>\uff084\uff09\u4e32\u53e3\u914d\u7f6e\uff08\u7528\u4e8e\u4e0a\u4f4d\u673a\u663e\u793a\u6536\u53d1\u6570\u636e\u65b9\u4fbf\u770b\u5230\u6548\u679c\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"1000\" height=\"733\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uart-1.png\" alt=\"\" class=\"wp-image-301\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uart-1.png 1000w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uart-1-300x220.png 300w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uart-1-768x563.png 768w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/figure>\n\n\n\n<p>\u914d\u7f6e\u4e32\u53e3\u6a21\u5f0f\u4e3aAsynchronous\uff0c\u786c\u4ef6\u6d41\u63a7\u5236Disable\u5c31\u53ef\u4ee5\uff0c\u6ce2\u7279\u7387\u5b57\u5bbd\u7b49\u53c2\u6570\u9ed8\u8ba4\u5373\u53ef\uff0c\u53e6\u5916\u6253\u5f00NVIC Setting\u4e0b\u9762\u7684 USART1 global interruput \u65b9\u4fbf\u63a5\u6536\u6765\u81ea\u4e0a\u4f4d\u673a\u7684\u6570\u636e\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uartnvic.png\"><img decoding=\"async\" loading=\"lazy\" width=\"1000\" height=\"727\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uartnvic.png\" alt=\"\" class=\"wp-image-302\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uartnvic.png 1000w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uartnvic-300x218.png 300w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uartnvic-768x558.png 768w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/a><\/figure>\n\n\n\n<p>\u65e2\u7136\u8bb2\u5230\u4e32\u53e3\u5c31\u987a\u4fbf\u63d0\u4e00\u4e0bDMA\u5427\uff0c\u6253\u5f00DMA\u53ef\u4ee5\u5927\u5927\u8282\u7ea6CPU\u8d44\u6e90\uff0c\u51cf\u8f7bCPU\u8d1f\u62c5\u3002\u5728DMA Setting\u9009\u9879\u5361\u4e0bAdd\u4e24\u4e2aDMA\u901a\u9053\uff08USART1_RX\u548cUSART1_TX\uff09,Mode\u6682\u90fd\u8bbe\u7f6e\u4e3aNormal\u6a21\u5f0f\uff0c\u5f53\u7136\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u4e3aCircle\u6a21\u5f0f\uff0c\u90a3\u6837DMA\u5c31\u4f1a\u4e0d\u505c\u7684\u6301\u7eed\u75af\u72c2\u5f80\u5916\u53d1\uff0c\u5728\u672c\u6d4b\u8bd5\u4e2d\u662f\u4e0d\u9700\u8981\u7684\u3002Data Width\u9ed8\u8ba4Byte.\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uartdma-1.png\"><img decoding=\"async\" loading=\"lazy\" width=\"998\" height=\"751\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uartdma-1.png\" alt=\"\" class=\"wp-image-304\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uartdma-1.png 998w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uartdma-1-300x226.png 300w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/uartdma-1-768x578.png 768w\" sizes=\"(max-width: 998px) 100vw, 998px\" \/><\/a><\/figure>\n\n\n\n<p>\u81f3\u6b64\u4e32\u53e3\u548cCAN \u603b\u7ebf\u7684\u8bbe\u7f6e\u5df2\u7ecf\u5b8c\u6bd5\u3002<\/p>\n\n\n\n<p>\uff085\uff09\u65f6\u949f\u6811\u914d\u7f6e<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/clock.png\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"737\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/clock-1024x737.png\" alt=\"\" class=\"wp-image-305\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/clock-1024x737.png 1024w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/clock-300x216.png 300w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/clock-768x553.png 768w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/clock.png 1117w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>\uff086\uff09\u8bbe\u7f6e\u9879\u76ee\u540d\u79f0\u548c\u6587\u4ef6\u8def\u5f84\u548cIDE<\/p>\n\n\n\n<p>IDE\u6839\u636e\u81ea\u5df1\u4f7f\u7528\u7684\u5f00\u53d1\u5de5\u5177\u9009\u62e9\uff0c\u6211\u8fd9\u91cc\u4f7f\u7528Keil V5\uff0c\u52fe\u9009Copy only the necessry library files\uff0c\u8fd9\u6837\u751f\u6210\u7684\u5de5\u7a0b\u5185\u53ea\u5305\u542b\u914d\u7f6e\u7528\u5230\u7684\u76f8\u5173\u5e93\u6587\u4ef6\u6ca1\u6709\u5197\u4f59\u3002\u52fe\u9009Generate peripheral initialization as a pair of &#8216;.c\/.h\u2019file per peripheral\uff0c\u6b64\u9009\u9879\u7684\u4f5c\u7528\u662f\u4f1a\u628a\u6bcf\u4e00\u4e2a\u5916\u8bbe\u7684\u76f8\u5173\u914d\u7f6e\u4ee3\u7801\u5206\u522b\u751f\u6210\u4e0d\u540c\u7684\u6e90\u6587\u4ef6\u548c\u5934\u6587\u4ef6\uff0c\u5de5\u7a0b\u66f4\u52a0\u6e05\u6d01\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/project.png\"><img decoding=\"async\" loading=\"lazy\" width=\"843\" height=\"638\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/project.png\" alt=\"\" class=\"wp-image-307\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/project.png 843w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/project-300x227.png 300w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/project-768x581.png 768w\" sizes=\"(max-width: 843px) 100vw, 843px\" \/><\/a><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/code.png\"><img decoding=\"async\" loading=\"lazy\" width=\"832\" height=\"470\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/code.png\" alt=\"\" class=\"wp-image-308\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/code.png 832w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/code-300x169.png 300w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/code-768x434.png 768w\" sizes=\"(max-width: 832px) 100vw, 832px\" \/><\/a><\/figure>\n\n\n\n<p>\uff087\uff09\u751f\u6210\u4ee3\u7801<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/generate.png\"><img decoding=\"async\" loading=\"lazy\" width=\"483\" height=\"150\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/generate.png\" alt=\"\" class=\"wp-image-310\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/generate.png 483w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/generate-300x93.png 300w\" sizes=\"(max-width: 483px) 100vw, 483px\" \/><\/a><\/figure><\/div>\n\n\n<p>\u76f4\u63a5GENERATE CODE\u3000\u5373\u53ef<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/finish.png\"><img decoding=\"async\" loading=\"lazy\" width=\"582\" height=\"114\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/finish.png\" alt=\"\" class=\"wp-image-311\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/finish.png 582w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/finish-300x59.png 300w\" sizes=\"(max-width: 582px) 100vw, 582px\" \/><\/a><\/figure><\/div>\n\n\n<p>\u751f\u6210\u5b8c\u6210\u540e\u53ef\u4ee5\u6253\u5f00\u6587\u4ef6\u5939\u770b\u5230\u751f\u6210\u7684\u6587\u4ef6\u76ee\u5f55\uff0c\u6216\u8005\u76f4\u63a5\u6253\u5f00\u5de5\u7a0b\u90fd\u53ef\u4ee5\u3002<\/p>\n\n\n\n<p class=\"has-vivid-cyan-blue-color has-text-color has-medium-font-size\">\u4ee3\u7801\u589e\u52a0\u548c\u4fee\u6539<\/p>\n\n\n\n<p>(1)\u589e\u52a0\u90e8\u5206CAN\u603b\u7ebf\u7684\u6536\u53d1\u51fd\u6570\u548c\u8fc7\u6ee4\u51fd\u6570<\/p>\n\n\n\n<p>\u6253\u5f00\u5de5\u7a0b\u76ee\u5f55\u4e0b\u7684Application\/User\u4e0b\u7684can.c\u6587\u4ef6, \u5728\u6700\u540e\u7684<br>\/* USER CODE BEGIN 1 *\/<\/p>\n\n\n\n<p>\/* USER CODE END 1 *\/<br>\u4e4b\u95f4\u589e\u52a0\u81ea\u5df1\u7684\u4ee3\u7801, \u5426\u5219\u5982\u679cSTM32CubeMX \u914d\u7f6e\u51fa\u9519\u9700\u8981\u4fee\u6539\u914d\u7f6e\u91cd\u65b0\u751f\u6210\u4ee3\u7801\u7684\u65f6\u5019,\u5c31\u4f1a\u8986\u76d6\u6389\u8fd9\u90e8\u5206\u4ee3\u7801,\u76f8\u5f53\u4e8e\u767d\u5199,\u6240\u4ee5\u4e00\u5b9a\u8981\u5199\u5728\u8fd9\u4e24\u4e2a\u6ce8\u91ca\u4e2d\u95f4\u5207\u8bb0 !!<\/p>\n\n\n\n<p>\u8fd9\u91cc\u6211\u628a\u6211\u7684\u4ee3\u7801\u8d34\u51fa\u6765\u4f9b\u5927\u5bb6\u4f7f\u7528, \u53d1\u73b0bug\u8bf7\u544a\u8bc9\u6211\u8c22\u8c22 !<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void CAN_FilterInit(CAN_HandleTypeDef *hcan)\n{\n\tCAN_FilterTypeDef CAN_FilterInitStructure;\n\tCAN_FilterInitStructure.FilterMode = CAN_FILTERMODE_IDMASK;\n\tCAN_FilterInitStructure.FilterScale = CAN_FILTERSCALE_32BIT;\n\tCAN_FilterInitStructure.FilterIdHigh = 0x2460;\n\tCAN_FilterInitStructure.FilterIdLow = 0x0000;\n\tCAN_FilterInitStructure.FilterMaskIdHigh = 0xF0E0;\n\tCAN_FilterInitStructure.FilterMaskIdLow = 0x0000;\n\tCAN_FilterInitStructure.FilterBank = 0;\n\tCAN_FilterInitStructure.FilterFIFOAssignment = CAN_RX_FIFO0;\n\tCAN_FilterInitStructure.FilterActivation = ENABLE;\n\tCAN_FilterInitStructure.SlaveStartFilterBank = 14;\n\tif(HAL_CAN_ConfigFilter(hcan,&amp;CAN_FilterInitStructure) != HAL_OK)\n\t{\n\t\tError_Handler();\n\t}\n\tif(HAL_CAN_ActivateNotification(hcan,CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)\n\t{\n\t\tError_Handler();\n\t}\n\tif(HAL_CAN_Start(hcan) != HAL_OK)\n\t{\n\t\tError_Handler();\n\t}\n}\n<\/code><\/pre>\n\n\n\n<p>\u5e76\u4e14\u8bb0\u5f97\u5728can.h\u4e2d\u7533\u660e\u4e00\u4e0b.<\/p>\n\n\n\n<p>(2) CAN \u603b\u7ebf\u7684\u6536\u53d1\u51fd\u6570\u4e32\u53e3\u7684\u63a5\u6536\u53d1\u9001\u5b8c\u6210\u56de\u8c03\u51fd\u6570\u6211\u76f4\u63a5\u653e\u5728main.c\u91cc\u9762\u4e86,\u8fd9\u91cc\u4e5f\u8d34\u51fa\u6765\u7ed9\u5927\u5bb6\u53c2\u8003(\u4e5f\u8981\u8bb0\u5f97\u5728main.c\u9760\u524d\u7684\u90e8\u5206\u7533\u660e\u4e00\u4e0b):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)\/\/CAN Receive\n{\n\tCAN_RxHeaderTypeDef RX_Header;\n\tHAL_CAN_GetRxMessage(hcan,CAN_RX_FIFO0,&amp;RX_Header,RX_Data);\n\tHAL_CAN_ActivateNotification(hcan,CAN_IT_RX_FIFO0_MSG_PENDING);\n}\n\nvoid CAN_Send_Msg(CAN_HandleTypeDef *hcan,uint8_t *msg,uint8_t len,uint32_t id)\/\/CAN Transmit\n{\n\tCAN_TxHeaderTypeDef Tx_Header;\n\tuint32_t TxMailBox;\n\t\n\tTx_Header.StdId = id;\n\tTx_Header.IDE = CAN_ID_STD;\n\tTx_Header.RTR = CAN_RTR_DATA;\n\tTx_Header.DLC = len;\n\t\n\tHAL_CAN_AddTxMessage(hcan,&amp;Tx_Header,msg,&amp;TxMailBox);\n}\n\nvoid HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)\n{\n\tif(huart == &amp;huart1)\n\t{\n\t\tHAL_UART_Receive_DMA(&amp;huart1,(uint8_t*)TX_Data,sizeof(TX_Data));\n\t}\t\n}\n\nvoid HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)\n{\n\tif(huart == &amp;huart1)\n\t{\n\t\tCAN_Send_Msg(&amp;hcan,TX_Data,sizeof(TX_Data),0x123);\n\t\tHAL_UART_Transmit_DMA(&amp;huart1,(uint8_t*)RX_Data,sizeof(RX_Data));\n\t}\n}\n\n<\/code><\/pre>\n\n\n\n<p>(3)\u6b64\u5916\u8bb0\u5f97\u5728Main\u51fd\u6570\u7684\u5f00\u5934\u5904\u5f00\u542f\u4e32\u53e3DMA\u63a5\u6536\u548c\u53d1\u9001,\u5e76\u5b9a\u4e49\u76f8\u5173\u53d8\u91cf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uint8_t RX_Data&#91;8];\nuint8_t TX_Data&#91;8];\nCAN_TxHeaderTypeDef TxHeader;\n\nCAN_FilterInit(&amp;hcan);\nHAL_UART_Transmit_DMA(&amp;huart1,(uint8_t*)RX_Data,sizeof(RX_Data));\nHAL_UART_Receive_DMA(&amp;huart1,(uint8_t*)TX_Data,sizeof(TX_Data));\n\n<\/code><\/pre>\n\n\n\n<p>\u6b64\u6d4b\u8bd5\u5b9e\u73b0\u7684\u529f\u80fd\u662f:\u63a5\u6536\u6765\u81ea\u4e32\u53e3\u7684\u6570\u636e,\u7136\u540e\u901a\u8fc7CAN\u603b\u7ebf\u53d1\u9001\u51fa\u53bb,\u56e0\u4e3a\u914d\u7f6e\u4e86\u56de\u73af\u6a21\u5f0f,\u4f1a\u6536\u5230\u4e00\u6a21\u4e00\u6837\u7684CAN\u6570\u636e\u8f93\u5165,\u63a5\u6536\u5230\u6570\u636e\u540e\u518d\u901a\u8fc7\u4e32\u53e3DMA\u65b9\u5f0f\u53d1\u51fa\u53bb\u4e0a\u4f4d\u673a\u663e\u793a,\u7c7b\u4f3c\u4e32\u53e3\u7684\u56de\u97f3\u5b9e\u9a8c,\u53ea\u4e0d\u8fc7\u4e2d\u95f4\u53c8\u4e32\u4e86\u4e00\u4e2aCAN\u7ebf,\u54c8\u54c8\u54c8\u6709\u70b9\u7ed5\u6211\u4e5f\u662f\u591f\u4e86\u2026<\/p>\n\n\n\n<p>\u7f16\u8bd1\u4e0b\u8f7d\u540e\u6548\u679c\u5982\u56fe<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/end.png\"><img decoding=\"async\" loading=\"lazy\" width=\"705\" height=\"559\" src=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/end.png\" alt=\"\" class=\"wp-image-313\" srcset=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/end.png 705w, https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/end-300x238.png 300w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><\/a><\/figure>\n\n\n\n<p>\u7ed3\u675f\uff0c\u7d2f\u4e86\uff0c\u62dc\u62dc<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"entry-summary\">\nSTM32CubeMX \u914d\u7f6e \u9996\u5148\u6253\u5f00S&hellip;\n<\/div>\n<div class=\"link-more\"><a href=\"https:\/\/jianwei.fun\/?p=292\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &ldquo;STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1&rdquo;<\/span>&hellip;<\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"vk_price":0},"categories":[6],"tags":[9,27],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1 - \u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jianwei.fun\/?p=292\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1 - \u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9\" \/>\n<meta property=\"og:description\" content=\"STM32CubeMX \u914d\u7f6e \u9996\u5148\u6253\u5f00S&hellip; Continue reading &ldquo;STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1&rdquo;&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jianwei.fun\/?p=292\" \/>\n<meta property=\"og:site_name\" content=\"\u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hou\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-28T06:16:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-13T02:08:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/sys-1024x576.png\" \/>\n<meta name=\"author\" content=\"Houjianwei\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hou\" \/>\n<meta name=\"twitter:site\" content=\"@hou\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"Houjianwei\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jianwei.fun\/?p=292#article\",\"isPartOf\":{\"@id\":\"https:\/\/jianwei.fun\/?p=292\"},\"author\":{\"name\":\"Houjianwei\",\"@id\":\"https:\/\/jianwei.fun\/#\/schema\/person\/88cea021deda9873b6e75b0687fd5956\"},\"headline\":\"STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1\",\"datePublished\":\"2021-10-28T06:16:39+00:00\",\"dateModified\":\"2022-09-13T02:08:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jianwei.fun\/?p=292\"},\"wordCount\":162,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/jianwei.fun\/#organization\"},\"keywords\":[\"CAN\",\"STM32\"],\"articleSection\":[\"STM32\"],\"inLanguage\":\"zh-CN\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/jianwei.fun\/?p=292#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jianwei.fun\/?p=292\",\"url\":\"https:\/\/jianwei.fun\/?p=292\",\"name\":\"STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1 - \u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9\",\"isPartOf\":{\"@id\":\"https:\/\/jianwei.fun\/#website\"},\"datePublished\":\"2021-10-28T06:16:39+00:00\",\"dateModified\":\"2022-09-13T02:08:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jianwei.fun\/?p=292#breadcrumb\"},\"inLanguage\":\"zh-CN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jianwei.fun\/?p=292\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jianwei.fun\/?p=292#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/jianwei.fun\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jianwei.fun\/#website\",\"url\":\"https:\/\/jianwei.fun\/\",\"name\":\"\u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9\",\"description\":\"\u83dc\u9e1f\u6210\u957f\u4e4b\u8def\",\"publisher\":{\"@id\":\"https:\/\/jianwei.fun\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jianwei.fun\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-CN\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jianwei.fun\/#organization\",\"name\":\"\u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9\",\"url\":\"https:\/\/jianwei.fun\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-CN\",\"@id\":\"https:\/\/jianwei.fun\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/cropped-cropped-monkey-1.png\",\"contentUrl\":\"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/cropped-cropped-monkey-1.png\",\"width\":203,\"height\":203,\"caption\":\"\u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9\"},\"image\":{\"@id\":\"https:\/\/jianwei.fun\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/hou\",\"https:\/\/twitter.com\/hou\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/jianwei.fun\/#\/schema\/person\/88cea021deda9873b6e75b0687fd5956\",\"name\":\"Houjianwei\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-CN\",\"@id\":\"https:\/\/jianwei.fun\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/88e7907f36adcd968cc7ce6e019c641a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/88e7907f36adcd968cc7ce6e019c641a?s=96&d=mm&r=g\",\"caption\":\"Houjianwei\"},\"sameAs\":[\"https:\/\/jianwei.fun\"],\"url\":\"https:\/\/jianwei.fun\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1 - \u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jianwei.fun\/?p=292","og_locale":"zh_CN","og_type":"article","og_title":"STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1 - \u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9","og_description":"STM32CubeMX \u914d\u7f6e \u9996\u5148\u6253\u5f00S&hellip; Continue reading &ldquo;STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1&rdquo;&hellip;","og_url":"https:\/\/jianwei.fun\/?p=292","og_site_name":"\u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9","article_publisher":"https:\/\/www.facebook.com\/hou","article_published_time":"2021-10-28T06:16:39+00:00","article_modified_time":"2022-09-13T02:08:54+00:00","og_image":[{"url":"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/sys-1024x576.png"}],"author":"Houjianwei","twitter_card":"summary_large_image","twitter_creator":"@hou","twitter_site":"@hou","twitter_misc":{"\u4f5c\u8005":"Houjianwei","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jianwei.fun\/?p=292#article","isPartOf":{"@id":"https:\/\/jianwei.fun\/?p=292"},"author":{"name":"Houjianwei","@id":"https:\/\/jianwei.fun\/#\/schema\/person\/88cea021deda9873b6e75b0687fd5956"},"headline":"STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1","datePublished":"2021-10-28T06:16:39+00:00","dateModified":"2022-09-13T02:08:54+00:00","mainEntityOfPage":{"@id":"https:\/\/jianwei.fun\/?p=292"},"wordCount":162,"commentCount":0,"publisher":{"@id":"https:\/\/jianwei.fun\/#organization"},"keywords":["CAN","STM32"],"articleSection":["STM32"],"inLanguage":"zh-CN","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jianwei.fun\/?p=292#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jianwei.fun\/?p=292","url":"https:\/\/jianwei.fun\/?p=292","name":"STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1 - \u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9","isPartOf":{"@id":"https:\/\/jianwei.fun\/#website"},"datePublished":"2021-10-28T06:16:39+00:00","dateModified":"2022-09-13T02:08:54+00:00","breadcrumb":{"@id":"https:\/\/jianwei.fun\/?p=292#breadcrumb"},"inLanguage":"zh-CN","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jianwei.fun\/?p=292"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jianwei.fun\/?p=292#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/jianwei.fun\/"},{"@type":"ListItem","position":2,"name":"STM32\u7cfb\u5217\u6587\u7ae0(1)\uff1aSTM32CubeMX\u914d\u7f6eCAN\u603b\u7ebf\u901a\u4fe1"}]},{"@type":"WebSite","@id":"https:\/\/jianwei.fun\/#website","url":"https:\/\/jianwei.fun\/","name":"\u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9","description":"\u83dc\u9e1f\u6210\u957f\u4e4b\u8def","publisher":{"@id":"https:\/\/jianwei.fun\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jianwei.fun\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-CN"},{"@type":"Organization","@id":"https:\/\/jianwei.fun\/#organization","name":"\u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9","url":"https:\/\/jianwei.fun\/","logo":{"@type":"ImageObject","inLanguage":"zh-CN","@id":"https:\/\/jianwei.fun\/#\/schema\/logo\/image\/","url":"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/cropped-cropped-monkey-1.png","contentUrl":"https:\/\/jianwei.fun\/wp-content\/uploads\/2021\/10\/cropped-cropped-monkey-1.png","width":203,"height":203,"caption":"\u4faf\u5148\u751f\u7684\u6280\u672f\u5c0f\u7ad9"},"image":{"@id":"https:\/\/jianwei.fun\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hou","https:\/\/twitter.com\/hou"]},{"@type":"Person","@id":"https:\/\/jianwei.fun\/#\/schema\/person\/88cea021deda9873b6e75b0687fd5956","name":"Houjianwei","image":{"@type":"ImageObject","inLanguage":"zh-CN","@id":"https:\/\/jianwei.fun\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/88e7907f36adcd968cc7ce6e019c641a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/88e7907f36adcd968cc7ce6e019c641a?s=96&d=mm&r=g","caption":"Houjianwei"},"sameAs":["https:\/\/jianwei.fun"],"url":"https:\/\/jianwei.fun\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/jianwei.fun\/index.php?rest_route=\/wp\/v2\/posts\/292"}],"collection":[{"href":"https:\/\/jianwei.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianwei.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianwei.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jianwei.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292"}],"version-history":[{"count":2,"href":"https:\/\/jianwei.fun\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions"}],"predecessor-version":[{"id":1409,"href":"https:\/\/jianwei.fun\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions\/1409"}],"wp:attachment":[{"href":"https:\/\/jianwei.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianwei.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianwei.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}