<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[【XR806开发板试用】驱动总线舵机例程]]></title><description><![CDATA[<p dir="auto"><strong>本文转自极术社区：<a href="https://aijishu.com/a/1060000000300549" target="_blank" rel="noopener noreferrer nofollow ugc">https://aijishu.com/a/1060000000300549</a><br />
作者：A.0王海智</strong></p>
<h1>简介</h1>
<p dir="auto">申请到XR806开发板很高兴，因为它可以基于鸿蒙L0系统下开发。在试用中，这个开发板的编译环境的搭建，程序的编写，都走很多的弯路，遇到了很多的坑。编译环境的搭建就用了很长的时间。也谢谢群里的大佬的帮助和极术小姐姐的鼓励，才能完成这次测试。</p>
<h1>编译环境</h1>
<p dir="auto">Windows下安装VMware虚拟机，虚拟机中安装Ubuntu20.04.2 64位桌面版。搭建教程是参考的<a href="https://aijishu.com/a/1060000000291606" target="_blank" rel="noopener noreferrer nofollow ugc">【XR806开发板试用】shell脚本一键配置XR806开发环境</a>。</p>
<h1>总线舵机说明</h1>
<p dir="auto">总线舵机：<br />
<img src="/assets/uploads/files/1645599166550-6f9d3af4-a523-4d76-bebd-c02812420b37.png" alt="6F9D3AF4-A523-4d76-BEBD-C02812420B37.png" class=" img-responsive img-markdown" width="760" height="570" /></p>
<h1>舵机参数说明</h1>
<p dir="auto"><img src="/assets/uploads/files/1645599173586-4144429779-62125cb61ad2.png" alt="4144429779-62125cb61ad2.png" class=" img-responsive img-markdown" width="623" height="400" /></p>
<p dir="auto">总线舵机是通过单线收发串口数据，通过之前做的RT-PI的扩展板实现。电路如图<br />
<img src="/assets/uploads/files/1645599184660-3560451891-62125ce8b39ac.png" alt="3560451891-62125ce8b39ac.png" class=" img-responsive img-markdown" width="482" height="308" /></p>
<h1>工作原理</h1>
<p dir="auto"><img src="/assets/uploads/files/1645599194680-2284335124-62125d18db03a.png" alt="2284335124-62125d18db03a.png" class=" img-responsive img-markdown" width="730" height="213" /></p>
<p dir="auto">XR806通过UART1串口发送十位十六进制的数据，扩展板将串口数据转换为单线串口和舵机通讯，完成总线舵机的控制。<br />
舵机数据协议图<br />
<img src="/assets/uploads/files/1645599214571-4012873550-62125c9097ecf.png" alt="4012873550-62125c9097ecf.png" class=" img-responsive img-markdown" width="645" height="367" /></p>
<h1>程序说明</h1>
<p dir="auto">程序结构图<br />
<img src="/assets/uploads/files/1645599226608-2163617501-62125d939e935.png" alt="2163617501-62125d939e935.PNG" class=" img-responsive img-markdown" width="232" height="274" /><br />
1.ohosdemo文件夹下的BUILD.gn文件</p>
<pre><code>group("ohosdemo"){
   deps = [
      #"TD-LED:app_TDLED",
      "uart_demo:app_uart",
     #"LED:app_led",
     # "hello_demo:app_hello",
       ]
       }
</code></pre>
<p dir="auto">2.uart_demo文件夹下的BUILD.gn文件</p>
<pre><code>import("//device/xradio/xr806/liteos_m/config.gni")

  static\_library("app\_uart") {  
    configs = \[\]  

  sources = \[  

    "src/main.c",
    #"src/test_flash.c",
    #"src/test_gpio.c",
    #"src/test_i2c.c",
    #"src/test_lowpower.c",
    #"src/test_pwm.c",
    #"src/test_reset.c",
    #"src/test_uart.c",
    #"src/test_watchdog.c",

   \]  

   cflags = board\_cflags  

   include\_dirs = board\_include\_dirs  
   include\_dirs += \[  

    "//kernel/liteos_m/kernel/arch/include",
    "include",
    "//base/iot_hardware/peripheral/interfaces/kits",

   \]  
   }
</code></pre>
<p dir="auto">3.uart_demo/src/main.c代码如下</p>
<pre><code>#include &lt;stdio.h&gt;
   #include "ohos\_init.h"
   #include "kernel/os/os.h"
   #include &lt;string.h&gt;
   #include "iot\_uart.h"
   #include "driver/chip/hal\_uart.h"
   #define UARTID UART1\_ID
   #define UART\_BUFFER\_MAXSIZE 50
   #define UART\_RECEIVE\_DATALED 30 

   const uint8\_t play\_Buffer\[10\] = {0xFA,0xAF,0x00,0x01,0x96,0x00,0x00,0x00,0x97,0xED};  
   const uint8\_t play\_Buffer1\[10\] = {0xFA,0xAF,0x00,0x01,0x00,0x00,0x00,0x00,0x01,0xED};  
   static OS\_Thread\_t g\_main\_thread;  
 
   static int uart\_init(void)  
   {  

   HAL_Status status = HAL_ERROR;
   UART_InitParam param;
   
   param.baudRate = 115200;   // 波特率为115200
   param.dataBits = UART_DATA_BITS_8;
   param.stopBits = UART_STOP_BITS_1;
   param.parity = UART_PARITY_NONE;
   param.isAutoHwFlowCtrl = 0;
   
   status = HAL_UART_Init(UARTID, &amp;param);
     if (status != HAL_OK)
       printf("uart init error %d\n", status);
   return status;

   }  
 
   static void MainThread(void \*arg)  
   {  

   unsigned char uart_buffer[UART_BUFFER_MAXSIZE];
   uart_init();
   
   while (1) {
       HAL_UART_Transmit_Poll(UARTID, (uint8_t *)play_Buffer, 10);
       LOS_Msleep(2000);
       HAL_UART_Transmit_Poll(UARTID, (uint8_t *)play_Buffer1, 10);
   
       LOS_Msleep(2000);
   
      }

    }  
 
    void UARTMain(void)  
   {  
    printf("UART Test Start\\n");  
    if (OS\_ThreadCreate(&amp;g\_main\_thread, "MainThread",   MainThread, NULL,  

      OS_THREAD_PRIO_APP, 4 * 1024) != OS_OK) {
   printf("[ERR] Create MainThread Failed\n");

    }  
   }  
 
   SYS\_RUN(UARTMain); // Harmony线程入口
</code></pre>
<p dir="auto">演示视频：<a href="https://www.bilibili.com/video/BV15m4y1o7fv?zw" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.bilibili.com/video/BV15m4y1o7fv?zw</a></p>
]]></description><link>https://bbs.aw-ol.com/topic/1063/xr806开发板试用-驱动总线舵机例程</link><generator>RSS for Node</generator><lastBuildDate>Sat, 17 Oct 2026 05:52:36 GMT</lastBuildDate><atom:link href="https://bbs.aw-ol.com/topic/1063.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 23 Feb 2022 06:55:53 GMT</pubDate><ttl>60</ttl></channel></rss>