目录
  • 一、准备工作
  • 二、编译代码
  • 三、测试

5.UART数据传输测试

该教程演示如何通过开发板的UART数据传输测试

一、准备工作

  • 准备1块BearPi-Pico H3863开发板

二、编译代码

在Windows下编译操作
  1. 点击工具栏中的“系统配置”,打开配置界面.

    Alt text

  2. 选择Support UART Sample

    Application  --->
        [*] Enable Sample.
        [*]     Enable the Sample of peripheral.
        [ ]         Enable all the sample of peripheral, it's just for build.
        [ ]         Support ADC Sample.
        [ ]         Support BLINKY Sample.
        [ ]         Support BUTTON Sample.
        [ ]         Support I2C Sample.
        [ ]         Support PINCTRL Sample.
        [ ]         Support PWM Sample.
        [ ]         Support SPI Sample.
        [ ]         Support SYSTICK Sample.
        [ ]         Support TASKS Test Sample.
        [ ]         Support TCXO Sample.
        [ ]         Support TIMER Sample.
        [*]         Support UART Sample.
                        UART Sample Configuration  --->
    
    
    
  3. 设置UART对应的id和GPIO,id设置为1,GPIO设置为15和16。

    UART Sample Configuration  --->
        (1) Choose UART bus id.
        (15) Choose UART TXD pin.
        (16) Choose UART RXD pin.
        [*] Choose UART poll transfer mode.
        [ ] Choose UART interrupt transfer mode.
    
    
  4. 按下"Save"键保存配置。

    Alt text

  5. 关键代码,位于application\samples\peripheral\uart\uart_demo.c

    static void *uart_task(const char *arg)
    {
        unused(arg);
        /* UART pinmux. */
        app_uart_init_pin();        //设置引脚复用
    
        /* UART init config. */
        app_uart_init_config();     //初始化uart
    
        ......
    
        while (1) {
            osal_msleep(UART_TASK_DURATION_MS);
    #if defined(CONFIG_UART_POLL_TRANSFER_MODE)
            osal_printk("uart%d poll mode send start!, len = %d\r\n", CONFIG_UART_BUS_ID, sizeof(g_app_uart_rx_buff));
            (void)uapi_watchdog_kick();
            if (uapi_uart_write(CONFIG_UART_BUS_ID, g_app_uart_tx_buff, UART_TRANSFER_SIZE, 0) == UART_TRANSFER_SIZE) {     //发送uart数据
                osal_printk("uart%d poll mode send back succ!\r\n", CONFIG_UART_BUS_ID);
            }
            if (uapi_uart_read(CONFIG_UART_BUS_ID, g_app_uart_rx_buff, UART_TRANSFER_SIZE, 0) > 0) {                        //接收uart数据
                osal_printk("uart%d poll mode receive succ!, g_app_uart_rx_buff = %s\r\n", CONFIG_UART_BUS_ID,
                            g_app_uart_rx_buff);
            }
    
    #endif
        ......
        }
    
        return NULL;
    }
    
  6. 编译烧录固件

    参考环境搭建教程编译烧录代码

三、测试

烧录固件后按下开发的复位按键,用杜邦线短接RXD和TXD引脚,观察串口消息打印。


uart1 poll mode send start!, len = 18
uart1 poll mode send back succ!
uart1 poll mode receive succ!, g_app_uart_rx_buff = Hello BearPi
uart1 poll mode send start!, len = 18
uart1 poll mode send back succ!
uart1 poll mode receive succ!, g_app_uart_rx_buff = Hello BearPi
uart1 poll mode send start!, len = 18
uart1 poll mode send back succ!
uart1 poll mode receive succ!, g_app_uart_rx_buff = Hello BearPi