{"id":870,"date":"2024-08-14T17:33:30","date_gmt":"2024-08-14T09:33:30","guid":{"rendered":"http:\/\/8.153.64.192\/?page_id=870"},"modified":"2024-08-16T14:15:28","modified_gmt":"2024-08-16T06:15:28","slug":"%e9%a9%b1%e5%8a%a8%e8%a1%a5%e5%85%85%ef%bc%9aexample_uart_rxidleirq","status":"publish","type":"page","link":"http:\/\/www.agm-support.com.cn\/index.php\/sample-page\/%e9%a9%b1%e5%8a%a8%e8%a1%a5%e5%85%85%ef%bc%9aexample_uart_rxidleirq\/","title":{"rendered":"\u9a71\u52a8\u8865\u5145\uff1aexample_uart_rxIdleIrq"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\/\/example_uart_rxIdleIrq.c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">#include \"example.h\"<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/\/\u7c7b\u4f3cidle\u4e2d\u65ad\u7684\u4f7f\u7528\u65b9\u5f0f\uff1a<br>\/\/\u4ee5 UART_INT_RX\uff08\u6536\u4e2d\u65ad\uff09\u548c UART_INT_RT\uff08\u6536\u8d85\u65f6\u4e2d\u65ad\uff09\u914d\u5408\u6765\u5b9e\u73b0idle\u4e2d\u65ad\u7684\u529f\u80fd\u3002<br>\/\/\u4e32\u53e3\u7684FIFO\u53ea\u670916\u4e2a\u5b57\u8282\uff0c\u901a\u8fc7UART_SetRxIntFifoLevel\u914d\u7f6e\u4e3aUART_INT_FIFO_HALF\u65f6\uff0c\u6bcf\u65368\u4e2a\u5b57\u8282\u4f1a\u6765\u4e00\u6b21UART_INT_RX\u4e2d\u65ad\u3002<br>\/\/\u5982\u679c\u6536\u53d6\u7684\u957f\u5ea6\u4e0d\u8db38\u4e2a\u5b57\u8282\u65f6\uff0c\u4f1a\u89e6\u53d1UART_INT_RT\u4e2d\u65ad\u3002<br>\/\/\u6570\u636e\u5904\u7406\u65f6\uff0c\u5982\u679c\u63a5\u6536\u4e0d\u5b9a\u957f\u6570\u636e\u8d85\u8fc78\u4e2a\u4ee5\u4e0a\u7684\uff0c\u8981\u901a\u8fc7UART_INT_RX\u4e2d\u65ad8\u4e2a8\u4e2a\u6765\u6536\u53d6\uff1b\u6700\u540e\u96f6\u788e\u7684\uff0c\u901a\u8fc7UART_INT_RT\u6765\u6536\u53d6\u3002<br>\/\/\u5168\u90e8\u6536\u53d6\u5b8c\u4ee5\u540e\uff0c\u7531UART_INT_RT\u4e2d\u65ad\u6807\u8bb0\u6765\u5224\u5b9a idle\u5b8c\u6574\u7684\u4e00\u5305\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">volatile char isRecvEnd = 0; \/\/\u662f\u5426\u6536\u53d6idle\u5b8c\u6574\u4e00\u5305<br>volatile char rcvLen = 0; \/\/rx\u6536\u53d6\u7684\u5305\u7684\u957f\u5ea6<br>char rxbuf[64]; \/\/rx\u6536\u53d6\u7684\u7f13\u5b58buff<br>void UART0_isr()<br>{<br>    if (UART_IsRawIntActive(UART0, UART_INT_RX)) {<br>        UART_ClearInt(UART0, UART_INT_RX);<br>        \/\/\u6ce8\u610f\uff1a\u8fd9\u65f6FIFO\u91cc\u67098\u4e2a\u5b57\u8282\u957f\u5ea6\uff0c\u4f46\u7279\u610f\u4e0d\u5168\u90e8\u6536\u53d6\u3002<br>        \/\/\u8fd9\u4e48\u505a\uff0c\u662f\u4e3a\u4e86\u4fdd\u8bc1\u4f20\u8f93\u6570\u636e\u521a\u597d\u662f8\u7684\u6574\u6570\u500d\u65f6\uff0c\u4ecd\u7136\u4f1a\u89e6\u53d1\u4e0b\u8fb9\u7684UART_INT_RT\u4e2d\u65ad\u3002<br>        UART_Receive(UART0, rxbuf + rcvLen, 7, 0); \/\/half: 16\/2=8\u3002<br>        rcvLen += 7;<br>    } else if (UART_IsRawIntActive(UART0, UART_INT_RT)) {<br>        UART_ClearInt(UART0, UART_INT_RT);<br>        rcvLen += UART_Receive(UART0, rxbuf + rcvLen, 8, 1); \/\/\u6700\u540e\u4e00\u4e2a\u53c2\u6570\u4e0d\u80fd\u4e3a0\uff0c\u4e3a0\u65f6UART_Receive\u662f\u4e0d\u4f1a\u8d85\u65f6\u9000\u51fa\u7684<br>        isRecvEnd = 1; \/\/idle\u4e00\u5305\u6536\u6ee1<br>    }<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">void TestUartRxIdleIqr(void)<br>{<br>    GPIO_AF_ENABLE(UART0_UARTRXD)<br>    GPIO_AF_ENABLE(UART0_UARTTXD);<br>    SYS_EnableAPBClock(APB_MASK_UART0);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">    UART_Init(UART0, 115200, UART_LCR_DATABITS_8, UART_LCR_STOPBITS_1, UART_LCR_PARITY_NONE, UART_LCR_FIFO_16);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">    UART_EnableInt(UART0, UART_INT_RT); \/\/\u914d\u7f6e \u6536\u8d85\u65f6\u4e2d\u65ad<br>    UART_EnableInt(UART0, UART_INT_RX); \/\/\u914d\u7f6e \u6536\u4e2d\u65ad<br>    UART_SetRxIntFifoLevel(UART0, UART_INT_FIFO_HALF); \/\/\u914d\u7f6eFIFO\u6536\u591a\u5c11\u5b57\u8282\u65f6\u4ea7\u751f\u6536\u4e2d\u65ad<br>    INT_EnableIRQ(UART0_IRQn, UART_PRIORITY);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">    UART_Send(UART0, \"test idleIrq\\r\\n\", strlen(\"test idleIrq\\r\\n\"));<br>    \/\/test<br>    while(1)<br>    {<br>        UTIL_IdleUs(500e3);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">        if (isRecvEnd == 1)<br>        {<br>          UART_Send(UART0, rxbuf, rcvLen);<br>          rcvLen = 0;<br>          isRecvEnd = 0;<br>        }<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">    }<br>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/example_uart_rxIdleIrq.c #include \"example.h\" \/\/\u7c7b\u4f3cidl [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2,"menu_order":12,"comment_status":"closed","ping_status":"closed","template":"","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","footnotes":""},"class_list":["post-870","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/870","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=870"}],"version-history":[{"count":3,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/870\/revisions"}],"predecessor-version":[{"id":873,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/870\/revisions\/873"}],"up":[{"embeddable":true,"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/pages\/2"}],"wp:attachment":[{"href":"http:\/\/www.agm-support.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}