{"id":74225,"date":"2024-01-03T09:18:16","date_gmt":"2024-01-03T01:18:16","guid":{"rendered":"\/\/www.dealsbon.com\/?p=74225"},"modified":"2024-01-03T09:18:16","modified_gmt":"2024-01-03T01:18:16","slug":"ljrhsyh","status":"publish","type":"post","link":"\/\/www.dealsbon.com\/blog\/74225.html","title":{"rendered":"\u4e86\u89e3\u5982\u4f55\u4f7f\u7528hal_uart_transmit"},"content":{"rendered":"

  \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528hal_uart_transmit\u8fd9\u4e00\u5173\u952e\u51fd\u6570\u3002\u4f5c\u4e3a\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\u5e38\u7528\u7684UART\u901a\u4fe1\u51fd\u6570\uff0chal_uart_transmit\u7684\u6b63\u786e\u4f7f\u7528\u5bf9\u4e8e\u7cfb\u7edf\u7684\u6b63\u5e38\u8fd0\u884c\u81f3\u5173\u91cd\u8981\u3002\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u60a8\u5c06\u80fd\u591f\u6e05\u6670\u5730\u638c\u63e1\u8be5\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u4e3a\u60a8\u7684\u9879\u76ee\u5f00\u53d1\u63d0\u4f9b\u6709\u529b\u652f\u6301\u3002<\/p>\n

\u4ec0\u4e48\u662fhal_uart_transmit\uff1f<\/h2>\n

  \u5728\u8fdb\u884c\u5d4c\u5165\u5f0f\u7cfb\u7edf\u5f00\u53d1\u65f6\uff0cUART\u901a\u4fe1\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u4e32\u884c\u901a\u4fe1\u534f\u8bae\u3002\u800chal_uart_transmit\u51fd\u6570\uff0c\u5219\u662f\u4e00\u79cd\u5728HAL\uff08Hardware Abstraction Layer\uff0c\u786c\u4ef6\u62bd\u8c61\u5c42\uff09\u4e2d\u7528\u4e8e\u5411UART\u53d1\u9001\u6570\u636e\u7684\u5173\u952e\u51fd\u6570\u3002\u901a\u8fc7\u8c03\u7528\u8be5\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u5411\u5916\u90e8\u8bbe\u5907\u4f20\u8f93\u6570\u636e\u7684\u529f\u80fd\u3002<\/p>\n

  hal_uart_transmit\u51fd\u6570\u7684\u57fa\u672c\u7528\u6cd5<\/h3>\n

  \u8981\u4f7f\u7528hal_uart_transmit\u51fd\u6570\uff0c\u60a8\u9996\u5148\u9700\u8981\u4e86\u89e3\u5176\u57fa\u672c\u7528\u6cd5\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u60a8\u9700\u8981\u63d0\u4f9b\u5f85\u53d1\u9001\u6570\u636e\u7684\u7f13\u51b2\u533a\u6307\u9488\u4ee5\u53ca\u6570\u636e\u7684\u957f\u5ea6\u4f5c\u4e3a\u51fd\u6570\u7684\u53c2\u6570\u3002\u5728\u8c03\u7528\u8be5\u51fd\u6570\u4e4b\u524d\uff0c\u60a8\u8fd8\u9700\u8981\u8fdb\u884cUART\u7684\u521d\u59cb\u5316\u8bbe\u7f6e\uff0c\u5305\u62ec\u6ce2\u7279\u7387\u3001\u6570\u636e\u4f4d\u3001\u6821\u9a8c\u4f4d\u548c\u505c\u6b62\u4f4d\u7b49\u53c2\u6570\u7684\u914d\u7f6e\u3002\u4e00\u65e6\u914d\u7f6e\u5b8c\u6210\uff0c\u60a8\u5c31\u53ef\u4ee5\u8c03\u7528hal_uart_transmit\u51fd\u6570\u53d1\u9001\u6570\u636e\u4e86\u3002<\/p>\n

  \u793a\u4f8b\uff1a<\/h4>\n

  \/\/ \u521d\u59cb\u5316UART\u8bbe\u7f6e<\/p>

  hal_uart_init(baud_rate, data_bits, parity, stop_bits);<\/p>

  \/\/ \u6570\u636e\u51c6\u5907<\/p>

  uint8_t data_buffer[] = {0x01, 0x02, 0x03, 0x04, 0x05};<\/p>

  uint8_t data_length = 5;<\/p>

  \/\/ \u8c03\u7528hal_uart_transmit\u51fd\u6570\u53d1\u9001\u6570\u636e<\/p>

  hal_uart_transmit(data_buffer, data_length);<\/p><\/code><\/pre>\n

  hal_uart_transmit\u51fd\u6570\u7684\u9ad8\u7ea7\u5e94\u7528<\/h3>\n

  \u9664\u4e86\u57fa\u672c\u7684\u6570\u636e\u53d1\u9001\u529f\u80fd\uff0chal_uart_transmit\u51fd\u6570\u8fd8\u53ef\u4ee5\u5e94\u7528\u4e8e\u66f4\u590d\u6742\u7684\u573a\u666f\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u8d85\u65f6\u673a\u5236\u3001\u9519\u8bef\u5904\u7406\u548c\u6570\u636e\u6d41\u63a7\u5236\u7b49\u529f\u80fd\uff0c\u8fdb\u4e00\u6b65\u63d0\u5347UART\u901a\u4fe1\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002\u53e6\u5916\uff0c\u9488\u5bf9\u4e0d\u540c\u7684\u5d4c\u5165\u5f0f\u5e73\u53f0\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u9488\u5bf9\u6027\u5730\u8c03\u6574\u8be5\u51fd\u6570\u7684\u53c2\u6570\u548c\u4f7f\u7528\u65b9\u6cd5\uff0c\u4ee5\u786e\u4fdd\u5176\u5728\u4e0d\u540c\u7cfb\u7edf\u4e0a\u7684\u517c\u5bb9\u6027\u3002<\/p>\n

  \u793a\u4f8b\uff1a<\/h4>\n

  \/\/ \u589e\u52a0\u8d85\u65f6\u673a\u5236<\/p>

  if(hal_uart_transmit_with_timeout(data_buffer, data_length, timeout) == HAL_UART_OK) {<\/p> \/\/ \u53d1\u9001\u6210\u529f<\/p>

  } else {<\/p> \/\/ \u53d1\u9001\u8d85\u65f6\u5904\u7406<\/p>

  }<\/p>

  \/\/ \u9519\u8bef\u5904\u7406<\/p>

  hal_uart_transmit_error_handler(hal_uart_transmit(data_buffer, data_length));<\/p><\/code><\/pre>\n

\u603b\u7ed3<\/h2>\n

  \u901a\u8fc7\u672c\u6587\u7684\u8bb2\u89e3\uff0c\u6211\u4eec\u6df1\u5165\u4e86\u89e3\u4e86hal_uart_transmit\u51fd\u6570\u7684\u57fa\u672c\u7528\u6cd5\u548c\u9ad8\u7ea7\u5e94\u7528\u3002<\/strong>\u65e0\u8bba\u662f\u5728\u7b80\u5355\u7684\u6570\u636e\u4f20\u8f93\u8fd8\u662f\u590d\u6742\u7684\u901a\u4fe1\u573a\u666f\u4e2d\uff0c\u6b63\u786e\u5730\u4f7f\u7528\u8fd9\u4e00\u5173\u952e\u51fd\u6570\u5bf9\u4e8e\u5d4c\u5165\u5f0f\u7cfb\u7edf\u5f00\u53d1\u6765\u8bf4\u90fd\u81f3\u5173\u91cd\u8981\u3002\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u80fd\u591f\u4e3a\u60a8\u5728\u5d4c\u5165\u5f0f\u7cfb\u7edf\u5f00\u53d1\u4e2d\u66f4\u597d\u5730\u4f7f\u7528hal_uart_transmit\u51fd\u6570\u63d0\u4f9b\u5e2e\u52a9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528hal_uart_transmit\u8fd9\u4e00\u5173\u952e\u51fd\u6570\u3002\u4f5c\u4e3a\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\u5e38\u7528\u7684UART\u901a\u4fe1\u51fd\u6570\uff0chal_uart_transmit\u7684\u6b63\u786e\u4f7f\u7528\u5bf9\u4e8e\u7cfb<\/p>\n","protected":false},"author":1,"featured_media":64183,"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":[52],"class_list":["post-74225","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-wxtx"],"_links":{"self":[{"href":"\/\/www.dealsbon.com\/wp-json\/wp\/v2\/posts\/74225"}],"collection":[{"href":"\/\/www.dealsbon.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/\/www.dealsbon.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/\/www.dealsbon.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/\/www.dealsbon.com\/wp-json\/wp\/v2\/comments?post=74225"}],"version-history":[{"count":0,"href":"\/\/www.dealsbon.com\/wp-json\/wp\/v2\/posts\/74225\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"\/\/www.dealsbon.com\/wp-json\/wp\/v2\/media\/64183"}],"wp:attachment":[{"href":"\/\/www.dealsbon.com\/wp-json\/wp\/v2\/media?parent=74225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/\/www.dealsbon.com\/wp-json\/wp\/v2\/categories?post=74225"},{"taxonomy":"post_tag","embeddable":true,"href":"\/\/www.dealsbon.com\/wp-json\/wp\/v2\/tags?post=74225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}