{"id":60080,"date":"2026-01-14T22:49:52","date_gmt":"2026-01-14T14:49:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/60080.html"},"modified":"2026-01-14T22:49:52","modified_gmt":"2026-01-14T14:49:52","slug":"%e5%b5%8c%e5%85%a5%e5%bc%8f%e4%b9%8b%e4%b8%b2%e5%8f%a3%e9%80%9a%e4%bf%a1","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/60080.html","title":{"rendered":"\u5d4c\u5165\u5f0f\u4e4b\u4e32\u53e3\u901a\u4fe1"},"content":{"rendered":"<p>\u63d0\u793a&#xff1a;CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1\u3001\u4ee3\u7801\u5b9e\u73b0<\/p>\n<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u4e00\u3001CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1<\/li>\n<li>\u4e8c\u3001\u4ee3\u7801\u5b9e\u73b0<\/li>\n<li>\n<ul>\n<li>1.\u53d1\u9001<\/li>\n<li>2.\u63a5\u53d7<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09\u3001\u5e38\u7528\u7535\u5e73\u6807\u51c6<\/li>\n<\/ul>\n<p>\u63d0\u793a&#xff1a;\u4ee5\u4e0b\u662f\u672c\u7bc7\u6587\u7ae0\u6b63\u6587\u5185\u5bb9&#xff0c;\u4e0b\u9762\u6848\u4f8b\u53ef\u4f9b\u53c2\u8003<\/p>\n<h2>\u4e00\u3001CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114144950-6967ad0ee93cd.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<li>\u6ce2\u7279\u7387\u914d\u7f6e&#xff1a;\u5e38\u7528115200\u30019600\u7b49 \u542b\u4e49&#xff1a;115200 \u6307\u7684\u5c31\u662f\u4e32\u53e3\u7684\u6ce2\u7279\u7387\u4e3a 115200 bit\/s&#xff0c;\u4e5f\u5c31\u662f\u7406\u8bba\u4e0a\u6bcf\u79d2\u53ef\u4ee5\u4f20\u8f93 115200 \u4e2a\u4e8c\u8fdb\u5236\u4f4d<\/li>\n<p>\u4f46\u662f&#xff0c;\u5b9e\u9645\u901a\u4fe1&#xff0c;\u4e32\u53e3\u9700\u8981&#xff1a; 1\u4f4d\u8d77\u59cb\u4f4d &#xff08;\u4f4e\u7535\u5e73&#xff09;&#043; 8\u4f4d\u6570\u636e\u4f4d &#043; 0\/1\u4f4d\u5947\u5076\u6821\u9a8c\u4f4d&#xff08;\u53ef\u6709\u53ef\u65e0&#xff09; &#043; 1\u4f4d\u505c\u6b62\u4f4d&#xff08;\u9ad8\u7535\u5e73&#xff09;<\/p>\n<p>1 \u4e2a Byte &#061; 8 \u4e2a bit&#xff0c;\u5728\u4e32\u53e3\u901a\u4fe1\u7684\u5e38\u89c1\u914d\u7f6e&#xff08;8 \u4f4d\u6570\u636e\u4f4d &#043; 1 \u4f4d\u505c\u6b62\u4f4d &#043; \u65e0\u6821\u9a8c&#xff09;\u4e0b&#xff0c;\u6bcf\u4f20\u8f93 1 \u4e2a\u5b57\u8282\u7684\u6709\u6548\u6570\u636e&#xff0c;\u5b9e\u9645\u9700\u8981\u53d1\u9001 1&#xff08;\u8d77\u59cb\u4f4d&#xff09;&#043;8&#xff08;\u6570\u636e\u4f4d&#xff09;&#043;1&#xff08;\u505c\u6b62\u4f4d&#xff09;&#061;10 bit\u3002 \u6309 115200 bit\/s \u8ba1\u7b97&#xff0c;\u5b9e\u9645\u6bcf\u79d2\u80fd\u4f20\u8f93\u7684\u6709\u6548\u5b57\u8282\u6570\u7ea6\u4e3a 115200 \u00f7 10 &#061; 11520 Byte\/s&#xff0c;\u4e5f\u5c31\u662f\u7ea6 11.25 KB\/s\u3002<\/p>\n<li>\u5f02\u6b65\u901a\u4fe1 \u4e32\u53e3\u53ea\u6709\u4e24\u6839\u7ebf&#xff0c;tx\u3001rx&#xff08;\u4ea4\u53c9\u8fde\u63a5&#xff09;&#xff0c;\u65e0\u65f6\u949f\u7ebf&#xff0c;\u901a\u8fc7\u6ce2\u7279\u7387\u540c\u6b65<\/li>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114144951-6967ad0f723a7.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> 3. \u4e2d\u65ad \u901a\u8fc7\u4e2d\u65ad\u63a5\u6536\u5916\u90e8\u53d1\u9001\u7684\u6d88\u606f&#xff0c;\u63d0\u9ad8CPU\u7684\u5229\u7528\u7387\u3002<\/p>\n<h2>\u4e8c\u3001\u4ee3\u7801\u5b9e\u73b0<\/h2>\n<h3>1.\u53d1\u9001<\/h3>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff08;\u793a\u4f8b&#xff09;&#xff1a;<\/p>\n<p><span class=\"token comment\">\/\/ \u53d1\u9001\u4ee5&#039;\\\\0&#039;\u7ed3\u5c3e\u7684\u5b57\u7b26\u4e32&#xff0c;\u5229\u7528strlen\u8ba1\u7b97\u957f\u5ea6<\/span><br \/>\n<span class=\"token class-name\">uint8_t<\/span> tx_str<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\u4e32\u53e3\u53d1\u9001\u6d4b\u8bd5\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u53d1\u9001\u5b57\u7b26\u4e32&#xff0c;\u8d85\u65f6\u65f6\u95f4100ms<\/span><br \/>\n<span class=\"token function\">HAL_UART_Transmit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>huart1<span class=\"token punctuation\">,<\/span> tx_str<span class=\"token punctuation\">,<\/span> <span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">char<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span>tx_str<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u7b80\u5316\u5199\u6cd5&#xff08;\u76f4\u63a5\u4f20\u5b57\u7b26\u4e32&#xff09;<\/span><br \/>\n<span class=\"token function\">HAL_UART_Transmit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>huart1<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">uint8_t<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token string\">&#034;Hello World!\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">14<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">\/\/ \u6ce8&#xff1a;&#034;Hello World!\\\\r\\\\n&#034; \u517114\u4e2a\u5b57\u8282&#xff08;\u542b\u6362\u884c\u7b26&#xff09;&#xff0c;\u4e5f\u53ef\u7528strlen\u8ba1\u7b97<\/span><\/p>\n<h3>2.\u63a5\u53d7<\/h3>\n<p>\u4ee3\u7801\u5982\u4e0b&#xff08;\u793a\u4f8b&#xff09;&#xff1a;<\/p>\n<p>&gt; \u9996\u5148\u5728main\u51fd\u6570\u91cc\u521d\u59cb\u5316\u8981\u5f00\u542f\u4e32\u53e3\u7a7a\u95f2\u4e2d\u65ad<\/p>\n<p>  <span class=\"token comment\">\/\/ \u5f00\u542f\u4e32\u53e3\u7a7a\u95f2\u4e2d\u65ad\u63a5\u6536&#xff08;\u6838\u5fc3\u51fd\u6570&#xff09;<\/span><br \/>\n  <span class=\"token function\">HAL_UARTEx_ReceiveToIdle_IT<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>huart1<span class=\"token punctuation\">,<\/span> uart_rx<span class=\"token punctuation\">,<\/span> <span class=\"token number\">50<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/**<br \/>\n * &#064;brief  \u4e32\u53e3\u7a7a\u95f2\u4e2d\u65ad\u56de\u8c03\u51fd\u6570&#xff08;\u4ec5\u4fdd\u7559LED\u63a7\u5236\u89e3\u6790&#xff09;<br \/>\n * &#064;param  huart: \u4e32\u53e3\u53e5\u67c4<br \/>\n * &#064;param  Size: \u5b9e\u9645\u63a5\u6536\u5b57\u8282\u6570<br \/>\n * &#064;retval \u65e0<br \/>\n *\/<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">HAL_UARTEx_RxEventCallback<\/span><span class=\"token punctuation\">(<\/span>UART_HandleTypeDef <span class=\"token operator\">*<\/span>huart<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">uint16_t<\/span> Size<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">if<\/span><span class=\"token punctuation\">(<\/span>huart<span class=\"token operator\">-&gt;<\/span>Instance <span class=\"token operator\">&#061;&#061;<\/span> USART1<span class=\"token punctuation\">)<\/span><br \/>\n  <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ 1. \u4fdd\u5b58\u63a5\u6536\u6570\u636e\u957f\u5ea6<\/span><br \/>\n    <span class=\"token class-name\">uint16_t<\/span> uart_rx_len <span class=\"token operator\">&#061;<\/span> Size<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token comment\">\/\/ 2. \u6e05\u7a7a\u89e3\u6790\u4e34\u65f6\u53d8\u91cf&#xff0c;\u907f\u514d\u6b8b\u7559<\/span><br \/>\n    <span class=\"token keyword\">char<\/span> cmd_key<span class=\"token punctuation\">[<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ \u6307\u4ee4\u5173\u952e\u5b57&#xff08;\u5982SET_LED&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> led_state <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span>        <span class=\"token comment\">\/\/ LED\u72b6\u6001\u53c2\u6570<\/span><br \/>\n    <span class=\"token keyword\">char<\/span> echo_buf<span class=\"token punctuation\">[<\/span><span class=\"token number\">64<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u56de\u663e\u7f13\u5b58<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ 3. \u6838\u5fc3&#xff1a;\u7528sscanf\u89e3\u6790\u4e32\u53e3\u6570\u636e<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u683c\u5f0f&#xff1a;SET_LED:0\/1 &#xff08;\u63a7\u5236LED&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> ret1 <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">sscanf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">char<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span>uart_rx_buf<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;%9[^:]:%d&#034;<\/span><span class=\"token punctuation\">,<\/span> cmd_key<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>led_state<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ 4. \u6839\u636e\u89e3\u6790\u7ed3\u679c\u6267\u884cLED\u63a7\u5236\u903b\u8f91<\/span><br \/>\n    <span class=\"token keyword\">if<\/span><span class=\"token punctuation\">(<\/span>ret1 <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span>  <span class=\"token comment\">\/\/ \u89e3\u6790\u5230\u201c\u5173\u952e\u5b57:\u6570\u5b57\u201d\u683c\u5f0f&#xff08;\u5982SET_LED:1&#xff09;<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n      <span class=\"token keyword\">if<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">strcmp<\/span><span class=\"token punctuation\">(<\/span>cmd_key<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;SET_LED&#034;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n      <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u6267\u884cLED\u63a7\u5236\u903b\u8f91<\/span><br \/>\n        <span class=\"token keyword\">if<\/span><span class=\"token punctuation\">(<\/span>led_state <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n          <span class=\"token function\">HAL_GPIO_WritePin<\/span><span class=\"token punctuation\">(<\/span>GPIOA<span class=\"token punctuation\">,<\/span> GPIO_PIN_5<span class=\"token punctuation\">,<\/span> GPIO_PIN_RESET<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n          <span class=\"token function\">sprintf<\/span><span class=\"token punctuation\">(<\/span>echo_buf<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;[OK] LED\u5df2\u5173\u95ed\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span><span class=\"token punctuation\">(<\/span>led_state <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n          <span class=\"token function\">HAL_GPIO_WritePin<\/span><span class=\"token punctuation\">(<\/span>GPIOA<span class=\"token punctuation\">,<\/span> GPIO_PIN_5<span class=\"token punctuation\">,<\/span> GPIO_PIN_SET<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n          <span class=\"token function\">sprintf<\/span><span class=\"token punctuation\">(<\/span>echo_buf<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;[OK] LED\u5df2\u6253\u5f00\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">else<\/span><br \/>\n        <span class=\"token punctuation\">{<\/span><br \/>\n          <span class=\"token function\">sprintf<\/span><span class=\"token punctuation\">(<\/span>echo_buf<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;[ERROR] LED\u53c2\u6570\u9519\u8bef&#xff08;\u4ec50\/1&#xff09;\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n      <span class=\"token punctuation\">}<\/span><br \/>\n      <span class=\"token keyword\">else<\/span><br \/>\n      <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">sprintf<\/span><span class=\"token punctuation\">(<\/span>echo_buf<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;[ERROR] \u672a\u77e5\u6307\u4ee4&#xff1a;%s\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> cmd_key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n      <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">else<\/span>  <span class=\"token comment\">\/\/ \u89e3\u6790\u5931\u8d25&#xff08;\u683c\u5f0f\u9519\u8bef&#xff09;<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n      <span class=\"token function\">sprintf<\/span><span class=\"token punctuation\">(<\/span>echo_buf<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;[ERROR] \u6307\u4ee4\u683c\u5f0f\u9519\u8bef&#xff01;\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n      <span class=\"token function\">sprintf<\/span><span class=\"token punctuation\">(<\/span>echo_buf <span class=\"token operator\">&#043;<\/span> <span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span>echo_buf<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u652f\u6301\u683c\u5f0f&#xff1a;SET_LED:0\/1\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ 5. \u56de\u663e\u5904\u7406\u7ed3\u679c<\/span><br \/>\n    <span class=\"token function\">HAL_UART_Transmit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>huart1<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">uint8_t<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span>echo_buf<span class=\"token punctuation\">,<\/span> <span class=\"token function\">strlen<\/span><span class=\"token punctuation\">(<\/span>echo_buf<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ 6. \u6e05\u7a7a\u7f13\u51b2\u533a&#xff0c;\u91cd\u65b0\u5f00\u542f\u7a7a\u95f2\u4e2d\u65ad&#xff08;\u5173\u952e&#xff09;<\/span><br \/>\n    <span class=\"token function\">memset<\/span><span class=\"token punctuation\">(<\/span>uart_rx_buf<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> UART_RX_BUF_SIZE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">HAL_UARTEx_ReceiveToIdle_IT<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>huart1<span class=\"token punctuation\">,<\/span> uart_rx_buf<span class=\"token punctuation\">,<\/span> UART_RX_BUF_SIZE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\">\/**<br \/>\n * &#064;brief  \u4e32\u53e3\u9519\u8bef\u56de\u8c03\u51fd\u6570<br \/>\n * &#064;retval \u65e0<br \/>\n *\/<\/span><br \/>\n<span class=\"token keyword\">void<\/span> <span class=\"token function\">HAL_UART_ErrorCallback<\/span><span class=\"token punctuation\">(<\/span>UART_HandleTypeDef <span class=\"token operator\">*<\/span>huart<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">if<\/span><span class=\"token punctuation\">(<\/span>huart<span class=\"token operator\">-&gt;<\/span>Instance <span class=\"token operator\">&#061;&#061;<\/span> USART1<span class=\"token punctuation\">)<\/span><br \/>\n  <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">memset<\/span><span class=\"token punctuation\">(<\/span>uart_rx_buf<span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> UART_RX_BUF_SIZE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">HAL_UARTEx_ReceiveToIdle_IT<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>huart1<span class=\"token punctuation\">,<\/span> uart_rx_buf<span class=\"token punctuation\">,<\/span> UART_RX_BUF_SIZE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">HAL_UART_Transmit<\/span><span class=\"token punctuation\">(<\/span><span class=\"token operator\">&amp;<\/span>huart1<span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">uint8_t<\/span><span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token string\">&#034;[ERROR] \u4e32\u53e3\u63a5\u6536\u9519\u8bef&#xff01;\\\\r\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">24<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">100<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n  <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>&gt; \u5728\u4e32\u53e3\u56de\u8c03\u51fd\u6570\u8fd8\u8981\u5f00\u542f\u4e32\u53e3\u7a7a\u95f2\u4e2d\u65ad<\/p>\n<p>**<\/p>\n<p>sscanf (uart_rx,\u201c%3s-%3s\u201d,\u6570\u7ec41, \u6570\u7ec42); \u4f8b\u5982\u53d1\u9001 123-456 123\u5b58\u8fdb\u6570\u7ec41 456\u5b58\u8fdb\u6570\u7ec42<\/p>\n<p>**<\/p>\n<h2>\u4e09\u3001\u5e38\u7528\u7535\u5e73\u6807\u51c6<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114144951-6967ad0f9523f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63d0\u793a&#xff1a;CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1\u3001\u4ee3\u7801\u5b9e\u73b0 \u6587\u7ae0\u76ee\u5f55\u4e00\u3001CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1\u4e8c\u3001\u4ee3\u7801\u5b9e\u73b01.\u53d1\u90012.\u63a5\u53d7\u4e09\u3001\u5e38\u7528\u7535\u5e73\u6807\u51c6\u63d0\u793a&#xff1a;\u4ee5\u4e0b\u662f\u672c\u7bc7\u6587\u7ae0\u6b63\u6587\u5185\u5bb9&#xff0c;\u4e0b\u9762\u6848\u4f8b\u53ef\u4f9b\u53c2\u8003<br \/>\n\u4e00\u3001CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1 \u6ce2\u7279\u7387\u914d\u7f6e&#xff1a;\u5e38\u7528115200\u30019600\u7b49 \u542b\u4e49&#xff1a;115200 \u6307\u7684\u5c31\u662f\u4e32\u53e3\u7684\u6ce2\u7279\u7387\u4e3a 115200 bit\/s&#xff0c;\u4e5f\u5c31\u662f\u7406\u8bba\u4e0a\u6bcf\u79d2\u53ef\u4ee5\u4f20\u8f93 115200 \u4e2a\u4e8c\u8fdb\u5236\u4f4d<br \/>\n\u4f46\u662f&#xff0c;\u5b9e\u9645\u901a\u4fe1<\/p>\n","protected":false},"author":2,"featured_media":60077,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[269,1813,427],"topic":[],"class_list":["post-60080","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-269","tag-1813","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5d4c\u5165\u5f0f\u4e4b\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/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:\/\/www.wsisp.com\/helps\/60080.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5d4c\u5165\u5f0f\u4e4b\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u63d0\u793a&#xff1a;CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1\u3001\u4ee3\u7801\u5b9e\u73b0 \u6587\u7ae0\u76ee\u5f55\u4e00\u3001CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1\u4e8c\u3001\u4ee3\u7801\u5b9e\u73b01.\u53d1\u90012.\u63a5\u53d7\u4e09\u3001\u5e38\u7528\u7535\u5e73\u6807\u51c6\u63d0\u793a&#xff1a;\u4ee5\u4e0b\u662f\u672c\u7bc7\u6587\u7ae0\u6b63\u6587\u5185\u5bb9&#xff0c;\u4e0b\u9762\u6848\u4f8b\u53ef\u4f9b\u53c2\u8003 \u4e00\u3001CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1 \u6ce2\u7279\u7387\u914d\u7f6e&#xff1a;\u5e38\u7528115200\u30019600\u7b49 \u542b\u4e49&#xff1a;115200 \u6307\u7684\u5c31\u662f\u4e32\u53e3\u7684\u6ce2\u7279\u7387\u4e3a 115200 bit\/s&#xff0c;\u4e5f\u5c31\u662f\u7406\u8bba\u4e0a\u6bcf\u79d2\u53ef\u4ee5\u4f20\u8f93 115200 \u4e2a\u4e8c\u8fdb\u5236\u4f4d \u4f46\u662f&#xff0c;\u5b9e\u9645\u901a\u4fe1\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/60080.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-14T14:49:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114144950-6967ad0ee93cd.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/60080.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/60080.html\",\"name\":\"\u5d4c\u5165\u5f0f\u4e4b\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-14T14:49:52+00:00\",\"dateModified\":\"2026-01-14T14:49:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/60080.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/60080.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/60080.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5d4c\u5165\u5f0f\u4e4b\u4e32\u53e3\u901a\u4fe1\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5d4c\u5165\u5f0f\u4e4b\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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:\/\/www.wsisp.com\/helps\/60080.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5d4c\u5165\u5f0f\u4e4b\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u63d0\u793a&#xff1a;CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1\u3001\u4ee3\u7801\u5b9e\u73b0 \u6587\u7ae0\u76ee\u5f55\u4e00\u3001CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1\u4e8c\u3001\u4ee3\u7801\u5b9e\u73b01.\u53d1\u90012.\u63a5\u53d7\u4e09\u3001\u5e38\u7528\u7535\u5e73\u6807\u51c6\u63d0\u793a&#xff1a;\u4ee5\u4e0b\u662f\u672c\u7bc7\u6587\u7ae0\u6b63\u6587\u5185\u5bb9&#xff0c;\u4e0b\u9762\u6848\u4f8b\u53ef\u4f9b\u53c2\u8003 \u4e00\u3001CubeMx\u5b9e\u73b0\u4e32\u53e3\u901a\u4fe1 \u6ce2\u7279\u7387\u914d\u7f6e&#xff1a;\u5e38\u7528115200\u30019600\u7b49 \u542b\u4e49&#xff1a;115200 \u6307\u7684\u5c31\u662f\u4e32\u53e3\u7684\u6ce2\u7279\u7387\u4e3a 115200 bit\/s&#xff0c;\u4e5f\u5c31\u662f\u7406\u8bba\u4e0a\u6bcf\u79d2\u53ef\u4ee5\u4f20\u8f93 115200 \u4e2a\u4e8c\u8fdb\u5236\u4f4d \u4f46\u662f&#xff0c;\u5b9e\u9645\u901a\u4fe1","og_url":"https:\/\/www.wsisp.com\/helps\/60080.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-14T14:49:52+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260114144950-6967ad0ee93cd.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/60080.html","url":"https:\/\/www.wsisp.com\/helps\/60080.html","name":"\u5d4c\u5165\u5f0f\u4e4b\u4e32\u53e3\u901a\u4fe1 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-14T14:49:52+00:00","dateModified":"2026-01-14T14:49:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/60080.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/60080.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/60080.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5d4c\u5165\u5f0f\u4e4b\u4e32\u53e3\u901a\u4fe1"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/60080","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=60080"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/60080\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/60077"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=60080"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=60080"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=60080"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=60080"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}