{"id":161731,"date":"2024-11-04T08:52:21","date_gmt":"2024-11-04T00:52:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/161731\/"},"modified":"2024-11-04T08:52:22","modified_gmt":"2024-11-04T00:52:22","slug":"%e5%9f%ba%e6%96%bc-stm32-%e7%9a%84%e5%be%aa%e7%92%b0%e6%8e%a5%e6%94%b6%e6%95%b8%e6%93%9a%e5%ba%ab%e6%87%89%e7%94%a8%e5%af%a6%e8%b8%90-stm32-%e5%be%aa%e7%92%b0%e6%8e%a5%e6%94%b6%e6%95%b8%e6%93%9a","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/161731\/","title":{"rendered":"\u57fa\u65bc STM32 \u7684\u5faa\u74b0\u63a5\u6536\u6578\u64da\u5eab\u61c9\u7528\u5be6\u8e10 (stm32 \u5faa\u74b0\u63a5\u6536\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e5%9f%ba%e6%96%bc-stm32-%e7%9a%84%e5%be%aa%e7%92%b0%e6%8e%a5%e6%94%b6%e6%95%b8%e6%93%9a%e5%ba%ab%e6%87%89%e7%94%a8%e5%af%a6%e8%b8%90-yCTIMNrAEI\">\u57fa\u65bc STM32 \u7684\u5faa\u74b0\u63a5\u6536\u6578\u64da\u5eab\u61c9\u7528\u5be6\u8e10<\/h1>\n<p>\u96a8\u8457\u7269\u806f\u7db2\u548c\u5d4c\u5165\u5f0f\u7cfb\u7d71\u7684\u5feb\u901f\u767c\u5c55\uff0c\u57fa\u65bc STM32 \u7684\u61c9\u7528\u8d8a\u4f86\u8d8a\u53d7\u5230\u95dc\u6ce8\u3002STM32 \u662f\u4e00\u7cfb\u5217\u57fa\u65bc ARM Cortex-M \u6838\u5fc3\u7684\u5fae\u63a7\u5236\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u5d4c\u5165\u5f0f\u7cfb\u7d71\u4e2d\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5229\u7528 STM32 \u5be6\u73fe\u5faa\u74b0\u63a5\u6536\u6578\u64da\u4e26\u5c07\u5176\u5b58\u5132\u5230\u6578\u64da\u5eab\u4e2d\u7684\u61c9\u7528\u5be6\u8e10\u3002<\/p>\n<h2 id=\"stm32-%e7%a1%ac%e9%ab%94%e6%9e%b6%e6%a7%8b%e6%a6%82%e8%bf%b0-yCTIMNrAEI\">STM32 \u786c\u9ad4\u67b6\u69cb\u6982\u8ff0<\/h2>\n<p>STM32 \u5fae\u63a7\u5236\u5668\u7cfb\u5217\u64c1\u6709\u591a\u7a2e\u578b\u865f\uff0c\u9069\u7528\u65bc\u4e0d\u540c\u7684\u61c9\u7528\u9700\u6c42\u3002\u5176\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u591a\u7a2e\u8655\u7406\u5668\u6838\u5fc3\u9078\u64c7\uff1a\u5982 Cortex-M0\u3001M3\u3001M4 \u548c M7\u3002<\/li>\n<li>\u8c50\u5bcc\u7684\u5916\u8a2d\u63a5\u53e3\uff1a\u5982 UART\u3001SPI\u3001I2C \u7b49\u3002<\/li>\n<li>\u4f4e\u529f\u8017\u8a2d\u8a08\uff0c\u9069\u5408\u65bc\u96fb\u6c60\u4f9b\u96fb\u7684\u61c9\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%be%aa%e7%92%b0%e6%8e%a5%e6%94%b6%e6%95%b8%e6%93%9a%e7%9a%84%e5%9f%ba%e6%9c%ac%e5%8e%9f%e7%90%86-yCTIMNrAEI\">\u5faa\u74b0\u63a5\u6536\u6578\u64da\u7684\u57fa\u672c\u539f\u7406<\/h2>\n<p>\u5faa\u74b0\u63a5\u6536\u6578\u64da\u7684\u904e\u7a0b\u901a\u5e38\u6d89\u53ca\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li>\u521d\u59cb\u5316 UART \u63a5\u53e3\u4ee5\u63a5\u6536\u6578\u64da\u3002<\/li>\n<li>\u8a2d\u7f6e\u63a5\u6536\u7de9\u885d\u5340\u4ee5\u5b58\u5132\u63a5\u6536\u5230\u7684\u6578\u64da\u3002<\/li>\n<li>\u4f7f\u7528\u4e2d\u65b7\u6216\u8f2a\u8a62\u65b9\u5f0f\u63a5\u6536\u6578\u64da\u3002<\/li>\n<li>\u5c07\u63a5\u6536\u5230\u7684\u6578\u64da\u9032\u884c\u8655\u7406\u4e26\u5b58\u5132\u5230\u6578\u64da\u5eab\u4e2d\u3002<\/li>\n<\/ol>\n<h2 id=\"%e5%af%a6%e7%8f%be%e6%ad%a5%e9%a9%9f-yCTIMNrAEI\">\u5be6\u73fe\u6b65\u9a5f<\/h2>\n<h3 id=\"1-%e7%a1%ac%e9%ab%94%e9%80%a3%e6%8e%a5-yCTIMNrAEI\">1. \u786c\u9ad4\u9023\u63a5<\/h3>\n<p>\u9996\u5148\uff0c\u5c07 STM32 \u5fae\u63a7\u5236\u5668\u8207\u8a08\u7b97\u6a5f\u6216\u5176\u4ed6\u8a2d\u5099\u901a\u904e UART \u9032\u884c\u9023\u63a5\u3002\u78ba\u4fdd\u6b63\u78ba\u914d\u7f6e TX \u548c RX \u5f15\u8173\uff0c\u4ee5\u4fbf\u6578\u64da\u80fd\u5920\u6b63\u78ba\u50b3\u8f38\u3002<\/p>\n<h3 id=\"2-%e5%88%9d%e5%a7%8b%e5%8c%96-uart-yCTIMNrAEI\">2. \u521d\u59cb\u5316 UART<\/h3>\n<pre><code>\nvoid UART_Init(void) {\n    \/\/ \u914d\u7f6e UART \u53c3\u6578\n    USART_InitTypeDef USART_InitStructure;\n    USART_InitStructure.USART_BaudRate = 9600;\n    USART_InitStructure.USART_WordLength = USART_WordLength_8b;\n    USART_InitStructure.USART_StopBits = USART_StopBits_1;\n    USART_InitStructure.USART_Parity = USART_Parity_No;\n    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;\n    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;\n\n    \/\/ \u521d\u59cb\u5316 UART\n    USART_Init(USART1, &amp;USART_InitStructure);\n    USART_Cmd(USART1, ENABLE);\n}\n<\/code><\/pre>\n<h3 id=\"3-%e6%8e%a5%e6%94%b6%e6%95%b8%e6%93%9a-yCTIMNrAEI\">3. \u63a5\u6536\u6578\u64da<\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4e2d\u65b7\u65b9\u5f0f\u4f86\u63a5\u6536\u6578\u64da\uff0c\u9019\u6a23\u53ef\u4ee5\u63d0\u9ad8\u7cfb\u7d71\u7684\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u63a5\u6536\u6578\u64da\u7684\u793a\u4f8b\u4ee3\u78bc\uff1a<\/p>\n<pre><code>\nvoid USART1_IRQHandler(void) {\n    if (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) {\n        char receivedChar = USART_ReceiveData(USART1);\n        \/\/ \u5c07\u63a5\u6536\u5230\u7684\u5b57\u7b26\u5b58\u5132\u5230\u7de9\u885d\u5340\n        buffer[index++] = receivedChar;\n        if (index &gt;= BUFFER_SIZE) {\n            index = 0; \/\/ \u5faa\u74b0\u63a5\u6536\n        }\n    }\n}\n<\/code><\/pre>\n<h3 id=\"4-%e6%95%b8%e6%93%9a%e5%ba%ab%e5%ad%98%e5%84%b2-yCTIMNrAEI\">4. \u6578\u64da\u5eab\u5b58\u5132<\/h3>\n<p>\u63a5\u6536\u5230\u7684\u6578\u64da\u53ef\u4ee5\u901a\u904e\u4e32\u53e3\u6216\u7db2\u7d61\u50b3\u8f38\u5230\u6578\u64da\u5eab\u3002\u9019\u88e1\u4ee5\u4f7f\u7528 HTTP POST \u8acb\u6c42\u5c07\u6578\u64da\u767c\u9001\u5230\u4f3a\u670d\u5668\u70ba\u4f8b\uff1a<\/p>\n<pre><code>\nvoid SendDataToServer(char* data) {\n    \/\/ \u4f7f\u7528 HTTP POST \u5c07\u6578\u64da\u767c\u9001\u5230\u4f3a\u670d\u5668\n    \/\/ \u5177\u9ad4\u5be6\u73fe\u4f9d\u8cf4\u65bc\u6240\u4f7f\u7528\u7684\u7db2\u7d61\u5eab\n}\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-yCTIMNrAEI\">\u7e3d\u7d50<\/h2>\n<p>\u57fa\u65bc STM32 \u7684\u5faa\u74b0\u63a5\u6536\u6578\u64da\u5eab\u61c9\u7528\u5be6\u8e10\u4e0d\u50c5\u80fd\u5920\u63d0\u9ad8\u6578\u64da\u63a5\u6536\u7684\u6548\u7387\uff0c\u9084\u80fd\u5920\u5be6\u73fe\u6578\u64da\u7684\u6301\u4e45\u5316\u5b58\u5132\u3002\u901a\u904e\u5408\u7406\u7684\u786c\u9ad4\u8a2d\u8a08\u548c\u8edf\u9ad4\u5be6\u73fe\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u5c07 STM32 \u61c9\u7528\u65bc\u5404\u7a2e\u7269\u806f\u7db2\u9805\u76ee\u4e2d\u3002\u82e5\u60a8\u5c0d\u65bc\u4f3a\u670d\u5668\u7684\u9078\u64c7\u6709\u8208\u8da3\uff0c\u5efa\u8b70\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u7684\u8cc7\u8a0a\uff0c\u4ee5\u4fbf\u70ba\u60a8\u7684\u9805\u76ee\u63d0\u4f9b\u7a69\u5b9a\u7684\u5f8c\u7aef\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u57fa\u65bcSTM32\u7684\u5faa\u74b0\u63a5\u6536\u6578\u64da\u5eab\u61c9\u7528\u5be6\u8e10\uff0c\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u8655\u7406\u8207\u5b58\u5132\uff0c\u63d0\u5347\u5d4c\u5165\u5f0f\u7cfb\u7d71\u6027\u80fd\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-161731","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/161731","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=161731"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/161731\/revisions"}],"predecessor-version":[{"id":161732,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/161731\/revisions\/161732"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=161731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=161731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=161731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}