﻿{"id":89,"date":"2010-05-22T09:20:22","date_gmt":"2010-05-22T01:20:22","guid":{"rendered":"http:\/\/nick.workao.org\/?p=89"},"modified":"2010-05-22T09:20:25","modified_gmt":"2010-05-22T01:20:25","slug":"stm32-%e5%85%a5%e9%97%a8%e6%95%99%e7%a8%8b-%e5%bc%82%e6%ad%a5%e4%b8%b2%e5%8f%a3%e5%8f%8c%e5%b7%a5%e9%80%9a%e8%ae%af","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/scm\/89","title":{"rendered":"STM32 \u5165\u95e8\u6559\u7a0b \u5f02\u6b65\u4e32\u53e3\u53cc\u5de5\u901a\u8baf"},"content":{"rendered":"<p><strong><span style=\"color: red;\">(\u4e00) STM32 \u7684 USART \u6a21\u62df\u4ecb\u7ecd<\/span><\/strong><\/p>\n<p>\u901a\u7528\u540c\u6b65\u5f02\u6b65\u6536\u53d1\u5668\uff08USART\uff09\u63d0\u4f9b\u4e86\u4e00\u79cd\u7075\u6d3b\u7684\u65b9\u6cd5\u6765\u4e0e\u4f7f\u7528\u5de5\u4e1a\u6807\u51c6NR \u5f02\u6b65\u4e32\u884c\u6570\u636e\u683c\u5f0f\u7684\u5916\u90e8\u8bbe\u5907\u4e4b\u95f4\u8fdb\u884c\u5168\u53cc\u5de5\u6570\u636e\u4ea4\u6362\u3002  USART\u5229\u7528\u5206\u6570\u6ce2\u7279\u7387\u53d1\u751f\u5668\u63d0\u4f9b\u5bbd\u8303\u56f4\u7684\u6ce2\u7279\u7387\u9009\u62e9\u3002\n\u5b83\u652f\u6301\u540c\u6b65\u5355\u5411\u901a\u4fe1\u548c\u534a\u53cc\u5de5\u5355\u7ebf\u901a\u4fe1\u3002\u5b83\u4e5f\u652f\u6301LIN(\u5c40\u90e8\u4e92\u8fde\u7f51)\uff0c\u667a\u80fd\u5361\u534f\u8bae\u548cIrDA(\u7ea2\u5916\u6570\u636e\u7ec4\u7ec7)SIR  ENDEC\u89c4\u8303\uff0c\u4ee5\u53ca\u8c03\u5236\u89e3\u8c03\u5668(CTS\/RTS)\u64cd\u4f5c\u3002\u5b83\u8fd8\u5141\u8bb8\u591a\u5904\u7406\u5668\u901a\u4fe1\u3002\u7528\u4e8e\u591a\u7f13\u51b2\u5668\u914d\u7f6e\u7684DMA\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5b9e\u73b0\u9ad8\u901f\u6570\u636e\u901a\u4fe1\u3002<\/p>\n<p>\u4e3b\u8981\u7279\u6027\uff1a\n\u5168\u53cc\u5de5\u7684\uff0c\u5f02\u6b65\u901a\u4fe1\nNR \u6807\u51c6\u683c\u5f0f\n\u5206\u6570\u6ce2\u7279\u7387\u53d1\u751f\u5668\u7cfb\u7edf\n-\u53d1\u9001\u548c\u63a5\u6536\u5171\u7528\u7684\u53ef\u7f16\u7a0b\u6ce2\u7279\u7387\uff0c\u6700\u9ad8\u52304.5Mbits\/s\n\u53ef\u7f16\u7a0b\u6570\u636e\u5b57\u957f\u5ea6\uff088\u4f4d\u62169\u4f4d\uff09\n\u53ef\u914d\u7f6e\u7684\u505c\u6b62\u4f4d\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0-\u652f\u63011\u62162\u4e2a\u505c\u6b62\u4f4d\nLIN\u4e3b\u53d1\u9001\u540c\u6b65\u65ad\u5f00\u7b26\u7684\u80fd\u529b\u4ee5\u53caLIN\u4ece\u68c0\u6d4b\u65ad\u5f00\u7b26\u7684\u80fd\u529b\n&#8211;\u00a0\u00a0\u5f53USART\u786c\u4ef6\u914d\u7f6e\u6210LIN\u65f6\uff0c\u751f\u621013\u4f4d\u65ad\u5f00\u7b26\uff1b\u68c0\u6d4b10\/11\u4f4d\u65ad\u5f00\u7b26\n\u53d1\u9001\u65b9\u4e3a\u540c\u6b65\u4f20\u8f93\u63d0\u4f9b\u65f6\u949f\nIRDA SIR \u7f16\u7801\u5668\u89e3\u7801\u5668\n&#8211;\u00a0\u00a0\u5728\u6b63\u5e38\u6a21\u5f0f\u4e0b\u652f\u63013\/16\u4f4d\u7684\u6301\u7eed\u65f6\u95f4\n\u667a\u80fd\u5361\u6a21\u62df\u529f\u80fd\n&#8211;\u00a0\u00a0\u667a\u80fd\u5361\u63a5\u53e3\u652f\u6301ISO7816\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0-3\u6807\u51c6\u91cc\u5b9a\u4e49\u7684\u5f02\u6b65\u534f\u8bae\u667a\u80fd\u5361\n&#8211;\u00a0\u00a0\u667a\u80fd\u5361\u7528\u5230\u76840.5\u548c1.5\u4e2a\u505c\u6b62\u4f4d\n\u5355\u7ebf\u534a\u53cc\u5de5\u901a\u4fe1\n\u4f7f\u7528DMA\u7684\u53ef\u914d\u7f6e\u7684\u591a\u7f13\u51b2\u5668\u901a\u4fe1\n&#8211;\u00a0\u00a0\u5728\u4fdd\u7559\u7684SRAM\u91cc\u5229\u7528\u96c6\u4e2d\u5f0fDMA\u7f13\u51b2\u63a5\u6536\/\u53d1\u9001\u5b57\u8282\n\u5355\u72ec\u7684\u53d1\u9001\u5668\u548c\u63a5\u6536\u5668\u4f7f\u80fd\u4f4d\n\u68c0\u6d4b\u6807\u5fd7\n&#8211;\u00a0\u00a0\u63a5\u6536\u7f13\u51b2\u5668\u6ee1\n&#8211;\u00a0\u00a0\u53d1\u9001\u7f13\u51b2\u5668\u7a7a\n&#8211;\u00a0\u00a0\u4f20\u8f93\u7ed3\u675f\u6807\u5fd7\n\u6821\u9a8c\u63a7\u5236\n&#8211;\u00a0\u00a0\u53d1\u9001\u6821\u9a8c\u4f4d\n&#8211;\u00a0\u00a0\u5bf9\u63a5\u6536\u6570\u636e\u8fdb\u884c\u6821\u9a8c\n\u56db\u4e2a\u9519\u8bef\u68c0\u6d4b\u6807\u5fd7\n&#8211;\u00a0\u00a0\u6ea2\u51fa\u9519\u8bef\n&#8211;\u00a0\u00a0\u566a\u97f3\u9519\u8bef\n&#8211;\u00a0\u00a0\u5e27\u9519\u8bef\n&#8211;\u00a0\u00a0\u6821\u9a8c\u9519\u8bef\n10\u4e2a\u5e26\u6807\u5fd7\u7684\u4e2d\u65ad\u6e90\n&#8211;\u00a0\u00a0CTS\u6539\u53d8\n&#8211;\u00a0\u00a0LIN\u65ad\u5f00\u7b26\u68c0\u6d4b\n&#8211;\u00a0\u00a0\u53d1\u9001\u6570\u636e\u5bc4\u5b58\u5668\n&#8211;\u00a0\u00a0\u53d1\u9001\u5b8c\u6210\n&#8211;\u00a0\u00a0\u63a5\u6536\u6570\u636e\u5bc4\u5b58\u5668\n&#8211;\u00a0\u00a0\u68c0\u6d4b\u5230\u603b\u7ebf\u4e3a\u7a7a\n&#8211;\u00a0\u00a0\u6ea2\u51fa\u9519\u8bef\n&#8211;\u00a0\u00a0\u5e27\u9519\u8bef\n&#8211;\u00a0\u00a0\u566a\u97f3\u9519\u8bef\n&#8211;\u00a0\u00a0\u6821\u9a8c\u9519\u8bef\n\u591a\u5904\u7406\u5668\u901a\u4fe1\u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0&#8211;\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0&#8211; \u5982\u679c\u5730\u5740\u4e0d\u5339\u914d\uff0c\u5219\u8fdb\u5165\u9759\u9ed8\u6a21\u5f0f\n\u4ece\u9759\u9ed8\u6a21\u5f0f\u4e2d\u5524\u9192\uff08\u901a\u8fc7\u7a7a\u95f2\u603b\u7ebf\u68c0\u6d4b\u6216\u5730\u5740\u6807\u5fd7\u68c0\u6d4b\uff09\n\u4e24\u79cd\u5524\u9192\u63a5\u6536\u5668\u7684\u65b9\u5f0f\n&#8211;\u00a0\u00a0\u5730\u5740\u4f4d\uff08MSB\uff09\n&#8211;\u00a0\u00a0\u7a7a\u95f2\u603b\u7ebf<\/p>\n<p><strong><span style=\"color: red;\">(\u4e8c) \u7a0b\u5e8f\u7f16\u5199\n<\/span><\/strong>\n<span style=\"color: darkorchid;\">(1) \u5728 RCC_Configuration \u51fd\u6570\u4e2d, \u6253\u5f00\u4e32\u53e3\u65f6\u949f<\/span>\n\/<em> Enable USART1, GPIOA, GPIOx and AFIO clocks <\/em>\/\nRCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA |  RCC_APB2Periph_GPIOx\n| RCC_APB2Periph_AFIO, ENABLE);<\/p>\n<p><span style=\"color: darkorchid;\">(2) \u8bbe\u7f6e\u4e32\u53e3\u7684 RTX, TDX IO \u53e3\u7684\u5c5e\u6027\n<\/span>void GPIO_Configuration(void)\n{\nGPIO_InitTypeDef GPIO_InitStructure;<\/p>\n<p>\/<em> Configure USART1 Rx (PA.10) as input floating <\/em>\/\nGPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;\nGPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;\nGPIO_Init(GPIOA, &#038;GPIO_InitStructure);<\/p>\n<p>\/<em> Configure USART1 Tx (PA.09) as alternate function push-pull <\/em>\/\nGPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;\nGPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;\nGPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;\nGPIO_Init(GPIOA, &#038;GPIO_InitStructure);\n}<\/p>\n<p><span style=\"color: darkorchid;\">(3) \u79fb\u690d fputc \u51fd\u6570\n<\/span>int fputc(int ch, FILE <em>f)\n{\n\/<\/em> Place your implementation of fputc here <em>\/\n\/<\/em> e.g. write a character to the USART *\/\nUSART_SendData(USART1, (u8) ch);<\/p>\n<p>\/<em> Loop until the end of transmission <\/em>\/\nwhile(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)\n{\n}<\/p>\n<p>return ch;\n}<\/p>\n<p><span style=\"color: darkorchid;\">(4) \u4e3b\u51fd\u6570\u4e2d\u521d\u59cb\u5316\u4e32\u53e3\u8bbe\u7f6e\n<\/span> USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;\nUSART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;\nUSART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;\nUSART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;\n\/<em> Configure the USART1 synchronous paramters <\/em>\/\nUSART_ClockInit(USART1, &#038;USART_ClockInitStructure);<\/p>\n<p>USART_InitStructure.USART_BaudRate = 115200;\nUSART_InitStructure.USART_WordLength = USART_WordLength_8b;\nUSART_InitStructure.USART_StopBits = USART_StopBits_1;\nUSART_InitStructure.USART_Parity = USART_Parity_No ;\nUSART_InitStructure.USART_HardwareFlowControl =<\/p>\n<p>USART_HardwareFlowControl_None;<\/p>\n<p>USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;\n\/<em> Configure USART1 basic and asynchronous paramters <\/em>\/\nUSART_Init(USART1, &#038;USART_InitStructure);<\/p>\n<p>\/<em> Enable USART1 <\/em>\/\nUSART_Cmd(USART1, ENABLE);<\/p>\n<p><span style=\"color: darkorchid;\">(5) \u7f16\u5199\u5e94\u7528\u7a0b\u5e8f\n<\/span> printf(&#8220;rn\u00a0 \u00a0\u6b22\u8fce\u6765\u5230\u9ea6\u601d\u7f51\u8bba\u575b\u00a0 \u00a0 rn&#8221;);\nprintf(&#8220;rn <a href=\"http:\/\/www.mystm32.com\/\" target=\"_blank\"><a href=\"http:\/\/www.mystm32.com\">http:\/\/www.mystm32.com<\/a><\/a> rn&#8221;);\nprintf(&#8220;rn Please Input Character From Keyboard rn&#8221;);\nwhile(1\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0)\n{\nif(USART_GetFlagStatus(USART1,USART_IT_RXNE)==SET)\n{\ni = USART_ReceiveData(USART1);\nprintf(&#8221;\u00a0\u00a0%c&#8221;,i&#038;0xFF);\u00a0 \u00a0\u00a0 \u00a0\u00a0 \u00a0\u00a0\u00a0\/<em> print the input char  <\/em>\/<\/p>\n<p>}\n}<\/p>\n<p><strong><span style=\"color: red;\">(\u4e09) \u8c03\u8bd5\u4eff\u771f\u7a0b\u5e8f<\/span><\/strong><\/p>\n<p>(1) \u4f7f\u7528Keil uVision3 \u901a\u8fc7ULINK 2\u4eff\u771f\u5668\u8fde\u63a5\u5b9e\u9a8c\u677f\uff0c\u6253\u5f00\u5b9e\u9a8c\u4f8b\u7a0b\u76ee\u5f55USART_TEST\u5b50\u76ee\u5f55\u4e0b\u7684USART.Uv2\u4f8b\u7a0b\uff0c\u7f16\u8bd1\u94fe\u63a5\u5de5\u7a0b\uff1b\n(2) \u4f7f\u7528MINI-STM32\u5f00\u53d1\u677f\u9644\u5e26\u7684\u4e32\u53e3\u7ebf\uff0c\u8fde\u63a5\u5f00\u53d1\u677f\u4e0a\u7684COM\u548cPC\u673a\u7684\u4e32\u53e3\uff1b\n(3)  \u5728PC\u673a\u4e0a\u8fd0\u884cwindows\u81ea\u5e26\u7684\u8d85\u7ea7\u7ec8\u7aef\u4e32\u53e3\u901a\u4fe1\u7a0b\u5e8f\uff08\u6ce2\u7279\u7387115200\u30011\u4f4d\u505c\u6b62\u4f4d\u3001\u65e0\u6821\u9a8c\u4f4d\u3001\u65e0\u786c\u4ef6\u6d41\u63a7\u5236\uff09\uff1b\u6216\u8005\u4f7f\u7528\u5176\u5b83\u4e32\u53e3\u901a\u4fe1\u7a0b\u5e8f\uff1b\n(4) \u9009\u62e9\u786c\u4ef6\u8c03\u8bd5\u6a21\u5f0f\uff0c\u70b9\u51fbMDK \u7684Debug\u83dc\u5355\uff0c\u9009\u62e9Start\/Stop Debug  Session\u9879\u6216Ctrl+F5\u952e\uff0c\u8fdc\u7a0b\u8fde\u63a5\u76ee\u6807\u677f\u5e76\u4e0b\u8f7d\u8c03\u8bd5\u4ee3\u7801\u5230\u76ee\u6807\u7cfb\u7edf\u4e2d\uff1b\n(5) \u4f8b\u7a0b\u6b63\u5e38\u8fd0\u884c\u4e4b\u540e\u4f1a\u5728\u8d85\u7ea7\u7ec8\u7aef\u663e\u793a\u4ee5\u4e0b\u4fe1\u606f\uff1a\n&#8221; \u6b22\u8fce\u6765\u5230\u9ea6\u601d\u7f51\u8bba\u575b&#8221;\n&#8220;<a href=\"http:\/\/www.mystm32.com\/\" target=\"_blank\"><a href=\"http:\/\/www.mystm32.com\">http:\/\/www.mystm32.com<\/a><\/a>&#8221;\n&#8220;Please Input Character From Keyboard&#8221;\n\u5728PC\u673a\u7684\u952e\u76d8\u4e0a\u8f93\u5165\u7684\u5b57\u7b26\uff0c\u5c06\u5728\u8d85\u7ea7\u7ec8\u7aef\u4e0a\u663e\u793a\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/nick.txtcc.com\/wp-content\/uploads\/remote_image\/2010\/05\/012023eik.gif\" border=\"0\" alt=\"\" \/> <img decoding=\"async\" id=\"aimg_587\" src=\"http:\/\/nick.txtcc.com\/wp-content\/uploads\/remote_image\/2010\/05\/012025cPu.jpg\" alt=\"1.jpg\" width=\"600\" \/><\/p>\n<div id=\"aimg_587_menu\"><a title=\"1.jpg\" href=\"http:\/\/www.mystm32.com\/bbs\/attachment.php?aid=587&#038;k=dafb23981e4746d9f7627442aa235b6a&#038;t=1257839459&#038;nothumb=yes&#038;sid=0678lPCMFwPjjaZ57b5BkD3QwanCSSvHxbRYN6UyXdZFyko\" target=\"_blank\"><strong>\u4e0b\u8f7d<\/strong><\/a> (44.9 KB)\n<div>2009-8-21 22:23<\/div>\n<\/div>\n<p>(6) \u4e5f\u53ef\u9009\u62e9<\/p>\n<p>\u8f6f\u4ef6<\/p>\n<p>\u8c03\u8bd5\u6a21\u5f0f\uff0c\u70b9\u51fbMDK \u7684Debug\u83dc\u5355\uff0c\u6253\u5f00\u4e32\u884c\u7a97\u53e3\uff0c\u9009\u62e9Start\/Stop Debug Session<\/p>\n<p>\u9879\u6216Ctrl+F5\u952e\uff0c\u5728\u4e32\u884c\u7a97\u53e3\u4e2d\u4e5f\u53ef\u770b\u5230\u4e0e\u7b2c\uff085\uff09\u6b65\u8d85\u7ea7\u7ec8\u7aef\u4e2d\u6240\u663e\u793a\u7684\u76f8\u540c\u5185\u5bb9\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>(\u4e00) STM32 \u7684 USART \u6a21\u62df\u4ecb\u7ecd \u901a\u7528\u540c\u6b65\u5f02\u6b65\u6536\u53d1\u5668\uff08USART\uff09\u63d0\u4f9b\u4e86\u4e00\u79cd\u7075\u6d3b\u7684\u65b9\u6cd5\u6765\u4e0e\u4f7f\u7528\u5de5\u4e1a\u6807\u51c6NR \u5f02\u6b65\u4e32\u884c\u6570\u636e\u683c\u5f0f\u7684\u5916\u90e8\u8bbe\u5907\u4e4b\u95f4\u8fdb\u884c\u5168\u53cc\u5de5\u6570\u636e\u4ea4\u6362\u3002 USART\u5229\u7528\u5206\u6570\u6ce2\u7279\u7387\u53d1\u751f&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39],"tags":[41,46,51],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-scm","tag-stm32","tag-46","tag-51"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":1,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":90,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/89\/revisions\/90"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}