{"id":38840,"date":"2023-09-30T17:33:11","date_gmt":"2023-09-30T09:33:11","guid":{"rendered":"https:\/\/www.techphant.cn\/?p=38840"},"modified":"2023-09-30T17:33:11","modified_gmt":"2023-09-30T09:33:11","slug":"szdjssj","status":"publish","type":"post","link":"https:\/\/www.techphant.cn\/blog\/38840.html","title":{"rendered":"STM32 UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e"},"content":{"rendered":"

  STM32 UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u662f\u4e00\u79cd\u5728STM32\u5fae\u63a7\u5236\u5668\u4e0a\u4f7f\u7528\u4e32\u884c\u901a\u4fe1\u63a5\u6536\u6570\u636e\u7684\u65b9\u6cd5\uff0c\u5b83\u53ef\u4ee5\u8ba9\u7a0b\u5e8f\u66f4\u5feb\u901f\u5730\u63a5\u6536\u5230\u8f93\u5165\u7684\u6570\u636e\u3002\u672c\u6587\u5c06\u4ecb\u7ecdSTM32 UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u7684\u539f\u7406\uff0c\u540c\u65f6\u4e5f\u4f1a\u7ed9\u51fa\u4e00\u4e2a\u5b9e\u9645\u7684\u4f8b\u5b50\uff0c\u4ee5\u52a0\u6df1\u5927\u5bb6\u5bf9\u5b83\u7684\u7406\u89e3\u3002<\/p>\n

STM32 UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u7684\u57fa\u672c\u539f\u7406<\/h2>\n

  STM32 UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u7684\u57fa\u672c\u539f\u7406\u662f\uff0c\u5f53\u63a5\u6536\u5230\u8f93\u5165\u7684\u6570\u636e\u65f6\uff0cSTM32\u5fae\u63a7\u5236\u5668\u5c31\u4f1a\u89e6\u53d1\u4e00\u4e2a\u4e2d\u65ad\uff0c\u4ece\u800c\u4f7f\u7a0b\u5e8f\u53ef\u4ee5\u7acb\u5373\u54cd\u5e94\u8f93\u5165\u7684\u6570\u636e\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u4f7f\u7a0b\u5e8f\u66f4\u5feb\u901f\u5730\u63a5\u6536\u5230\u8f93\u5165\u7684\u6570\u636e\uff0c\u800c\u4e0d\u7528\u62c5\u5fc3\u6570\u636e\u4e22\u5931\u7684\u95ee\u9898\u3002<\/p>\n

  \u4e2d\u65ad\u65b9\u5f0f\u7684\u4f18\u70b9<\/h3>\n

  \u4f7f\u7528STM32 UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7a0b\u5e8f\u66f4\u5feb\u901f\u5730\u63a5\u6536\u5230\u8f93\u5165\u7684\u6570\u636e\uff0c\u4ece\u800c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6548\u7387\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u4e2d\u65ad\u65b9\u5f0f\u53ef\u4ee5\u907f\u514d\u6570\u636e\u4e22\u5931\u7684\u60c5\u51b5\uff0c\u4f7f\u5f97\u7a0b\u5e8f\u66f4\u52a0\u7a33\u5b9a\u3002<\/p>\n

  \u4e2d\u65ad\u65b9\u5f0f\u7684\u7f3a\u70b9<\/h3>\n

  \u4f7f\u7528STM32 UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u7684\u65b9\u5f0f\uff0c\u4f1a\u5360\u7528\u5927\u91cf\u7684\u7cfb\u7edf\u8d44\u6e90\uff0c\u4ece\u800c\u964d\u4f4e\u7cfb\u7edf\u7684\u6548\u7387\u3002\u6b64\u5916\uff0c\u5982\u679c\u7a0b\u5e8f\u4e2d\u51fa\u73b0\u4e86bug\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u7cfb\u7edf\u51fa\u73b0\u5f02\u5e38\uff0c\u4ece\u800c\u5f71\u54cd\u7a0b\u5e8f\u7684\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n

\u5b9e\u9645\u7684\u4f8b\u5b50<\/h2>\n

  \u4e0b\u9762\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u5b9e\u9645\u7684\u4f8b\u5b50\uff0c\u8be5\u4f8b\u5b50\u4f7f\u7528STM32 UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u7684\u65b9\u5f0f\uff0c\u5c06\u63a5\u6536\u5230\u7684\u6570\u636e\u6253\u5370\u5230\u4e32\u53e3\u4e0a\uff1a<\/p>\n

#include  

  \/\/\u4e2d\u65ad\u670d\u52a1\u51fd\u6570<\/p>

  void USART1_IRQHandler(void)<\/p>

  {<\/p>

   uint8_t data;<\/p>

   \/\/\u5982\u679c\u662f\u63a5\u6536\u4e2d\u65ad<\/p>

   if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)<\/p>

   {<\/p>

  \/\/\u8bfb\u53d6\u63a5\u6536\u5230\u7684\u6570\u636e<\/p>

  data = USART_ReceiveData(USART1);<\/p>

  \/\/\u5c06\u6570\u636e\u6253\u5370\u5230\u4e32\u53e3<\/p>

  USART_SendData(USART1, data);<\/p>

   }<\/p>

  }<\/p>

  int main(void)<\/p>

  {<\/p>

   \/\/\u521d\u59cb\u5316\u4e32\u53e3<\/p>

   USART_InitTypeDef USART_InitStruct;<\/p>

   USART_InitStruct.USART_BaudRate = 9600;<\/p>

   USART_InitStruct.USART_WordLength = USART_WordLength_8b;<\/p>

   USART_InitStruct.USART_StopBits = USART_StopBits_1;<\/p>

   USART_InitStruct.USART_Parity = USART_Parity_No;<\/p>

   USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;<\/p>

   USART_Init(USART1, &USART_InitStruct);<\/p>

   \/\/\u4f7f\u80fd\u63a5\u6536\u4e2d\u65ad<\/p>

   USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);<\/p>

   \/\/\u4f7f\u80fd\u4e32\u53e3<\/p>

   USART_Cmd(USART1, ENABLE);<\/p>

   while(1);<\/p>

  }<\/p><\/code><\/pre>\n

  \u4ece\u4e0a\u9762\u7684\u4ee3\u7801\u53ef\u4ee5\u770b\u51fa\uff0c\u6211\u4eec\u9996\u5148\u521d\u59cb\u5316\u4e32\u53e3\uff0c\u7136\u540e\u4f7f\u80fd\u63a5\u6536\u4e2d\u65ad\uff0c\u6700\u540e\u4f7f\u80fd\u4e32\u53e3\u3002\u5f53\u63a5\u6536\u5230\u8f93\u5165\u7684\u6570\u636e\u65f6\uff0cSTM32\u5fae\u63a7\u5236\u5668\u5c31\u4f1a\u89e6\u53d1\u4e00\u4e2a\u4e2d\u65ad\uff0c\u4ece\u800c\u4f7f\u7a0b\u5e8f\u53ef\u4ee5\u7acb\u5373\u54cd\u5e94\u8f93\u5165\u7684\u6570\u636e\uff0c\u5e76\u5c06\u6570\u636e\u6253\u5370\u5230\u4e32\u53e3\u4e0a\u3002<\/p>\n

\u603b\u7ed3<\/h2>\n

  \u672c\u6587\u4ecb\u7ecd\u4e86STM32 UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u7684\u539f\u7406\uff0c\u4ee5\u53ca\u4e00\u4e2a\u5b9e\u9645\u7684\u4f8b\u5b50\u3002<\/strong>STM32 UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u7684\u65b9\u5f0f\u53ef\u4ee5\u4f7f\u7a0b\u5e8f\u66f4\u5feb\u901f\u5730\u63a5\u6536\u5230\u8f93\u5165\u7684\u6570\u636e\uff0c\u800c\u4e0d\u7528\u62c5\u5fc3\u6570\u636e\u4e22\u5931\u7684\u95ee\u9898\uff0c\u4f46\u662f\u4f1a\u5360\u7528\u5927\u91cf\u7684\u7cfb\u7edf\u8d44\u6e90\uff0c\u4ece\u800c\u964d\u4f4e\u7cfb\u7edf\u7684\u6548\u7387\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

STM32UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u662f\u4e00\u79cd\u5728STM32\u5fae\u63a7\u5236\u5668\u4e0a\u4f7f\u7528\u4e32\u884c\u901a\u4fe1\u63a5\u6536\u6570\u636e\u7684\u65b9\u6cd5\uff0c\u5b83\u53ef\u4ee5\u8ba9\u7a0b\u5e8f\u66f4\u5feb\u901f\u5730\u63a5\u6536\u5230\u8f93\u5165\u7684\u6570\u636e\u3002\u672c\u6587\u5c06\u4ecb\u7ecdSTM32UART\u4e2d\u65ad\u63a5\u6536\u6570\u636e\u7684<\/p>\n","protected":false},"author":1,"featured_media":4132,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"categories":[36],"tags":[287],"class_list":["post-38840","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-stm32"],"_links":{"self":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts\/38840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/comments?post=38840"}],"version-history":[{"count":0,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/posts\/38840\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/media\/4132"}],"wp:attachment":[{"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/media?parent=38840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/categories?post=38840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techphant.cn\/wp-json\/wp\/v2\/tags?post=38840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}