0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

体验linux下杰发7802x开发串口不定长收发实验

华仔的编程随笔 来源:华仔的编程随笔 作者:华仔的编程随笔 2023-06-04 15:37 次阅读

在这篇的基础之上,我们今天学习使用AC7802的串口收发。

1、把原来的工程复制一份到新的文件夹,并重命名为AC7802_UART工程。

2、新建Uart.h、Uart.c,内容如下:

#ifndef UART_H

#define UART_H

#include "ac780x_uart.h"

void UART_Cfg_Init(void);

#endif

Uart.c

#include

#include "ac780x_gpio.h"

#include "ac780x_uart_reg.h"

#include "Uart.h"

#define RX_BUF_LEN 100U

uint8_t g_rxLen = 0; /*!< 串口接收长度变量 */

uint8_t g_txLen = 0; /* !< 串口发送长度变量 */

uint8_t g_txCnt = 0;

uint8_t g_rxBuf[RX_BUF_LEN] = {0}; /* !< 串口接收数组 */

/*!

  • @brief 串口回调函数
  • @param void *device:UART_Type pointer
    uint32_t wpara:UART lsr0 register
    uint32_t lpara:UART lsr1 register
  • @return none
    */
    void UART_Callback(void *device, uint32_t wpara, uint32_t lpara)
    {
    UART_Type *Uart_Device = (UART_Type *)device;

/*! 串口接收中断 */

if(wpara & UART_LSR0_DR_Msk)

{

g_rxBuf[g_rxLen++] = UART_ReceiveData(Uart_Device);

if(g_rxLen > RX_BUF_LEN)

{

g_rxLen = 0;

}

}

/*!< 发送fifo空中断 */

if(Uart_Device->IER & UART_IER_ETXE_Msk)

{

UART_SendData(Uart_Device,g_rxBuf[g_txCnt++]);

if(g_txCnt >= g_txLen)

{

g_txCnt = 0;

UART_SetTXEInterrupt(Uart_Device, DISABLE);

}

}

/*!< 串口空闲中断 */

if(lpara & UART_LSR1_IDLE_Msk)

{

g_txLen = g_rxLen;

g_rxLen = 0;

UART_SetTXEInterrupt(Uart_Device, ENABLE);

}

}

/*!

  • @brief uart configuration init
  • @param none
  • @return none
    */
    void UART_Cfg_Init(void)
    {
    UART_ConfigType uart_config;

GPIO_SetFunc(GPIOA, GPIO_PIN4, GPIO_FUN3); /*! uart tx */

GPIO_SetFunc(GPIOA, GPIO_PIN5, GPIO_FUN3); /* ! uart rx */

uart_config.baudrate = 115200; /*! 波特率115200 */

uart_config.dataBits = UART_WORD_LEN_8BIT; /* ! 数据8bit */

uart_config.stopBits = UART_STOP_1BIT; /* ! 停止位1bit */

uart_config.fifoByteEn = DISABLE;

uart_config.sampleCnt = UART_SMP_CNT0; /* ! 16倍采样 */

uart_config.callBack = UART_Callback; /* ! 回调函数设置 */

UART_Init(UART1,&uart_config); /*! 串口初始化 */

UART_SetRXNEInterrupt(UART1, ENABLE); /*! 串口接收中断使能 */

UART_SetIdleFuncEn(UART1, ENABLE);

UART_SetIdleInterrupt(UART1, ENABLE); /*! 使能串口空闲中断 */

NVIC_SetPriority(UART1_IRQn, 3); /*! 串口中断优先级 */

NVIC_ClearPendingIRQ(UART1_IRQn);

NVIC_EnableIRQ(UART1_IRQn);

}

3、修改makefile内容中的TARGET 为:AC7802_UART。去掉原来gpio.c,新建Uart.c,增加ac78x_uart.c:

C sources

C_SOURCES =

Src/main.c

Src/AC7802x_irq_cb.c

Src/AC7802x_msp.c

Src/system_AC7802x.c

Drivers/ATC_Driver/Src/ac780x_gpio.c

Drivers/ATC_Driver/Src/ac780x_ckgen.c

Drivers/ATC_Driver/Src/ac780x_spm.c

Drivers/ATC_Driver/Src/ac780x_uart.c

User/Src/Uart.c

4、make结果如下:

lugl@lugl-virtual-machine:~/ac7802/AC7802_UART$ make

mkdir build

arm-none-eabi-gcc -c -mcpu=cortex-m0plus -mthumb -IInc -IDrivers/ATC_Driver/Inc -IDrivers/Device/Include -IDrivers/Device -IDrivers/Device/Include/CMSIS -IUser/Inc -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/main.d" -Wa,-a,-ad,-alms=build/main.lst Src/main.c -o build/main.o

arm-none-eabi-gcc -c -mcpu=cortex-m0plus -mthumb -IInc -IDrivers/ATC_Driver/Inc -IDrivers/Device/Include -IDrivers/Device -IDrivers/Device/Include/CMSIS -IUser/Inc -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/AC7802x_irq_cb.d" -Wa,-a,-ad,-alms=build/AC7802x_irq_cb.lst Src/AC7802x_irq_cb.c -o build/AC7802x_irq_cb.o

arm-none-eabi-gcc -c -mcpu=cortex-m0plus -mthumb -IInc -IDrivers/ATC_Driver/Inc -IDrivers/Device/Include -IDrivers/Device -IDrivers/Device/Include/CMSIS -IUser/Inc -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/AC7802x_msp.d" -Wa,-a,-ad,-alms=build/AC7802x_msp.lst Src/AC7802x_msp.c -o build/AC7802x_msp.o

arm-none-eabi-gcc -c -mcpu=cortex-m0plus -mthumb -IInc -IDrivers/ATC_Driver/Inc -IDrivers/Device/Include -IDrivers/Device -IDrivers/Device/Include/CMSIS -IUser/Inc -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/system_AC7802x.d" -Wa,-a,-ad,-alms=build/system_AC7802x.lst Src/system_AC7802x.c -o build/system_AC7802x.o

arm-none-eabi-gcc -c -mcpu=cortex-m0plus -mthumb -IInc -IDrivers/ATC_Driver/Inc -IDrivers/Device/Include -IDrivers/Device -IDrivers/Device/Include/CMSIS -IUser/Inc -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ac780x_gpio.d" -Wa,-a,-ad,-alms=build/ac780x_gpio.lst Drivers/ATC_Driver/Src/ac780x_gpio.c -o build/ac780x_gpio.o

arm-none-eabi-gcc -c -mcpu=cortex-m0plus -mthumb -IInc -IDrivers/ATC_Driver/Inc -IDrivers/Device/Include -IDrivers/Device -IDrivers/Device/Include/CMSIS -IUser/Inc -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ac780x_ckgen.d" -Wa,-a,-ad,-alms=build/ac780x_ckgen.lst Drivers/ATC_Driver/Src/ac780x_ckgen.c -o build/ac780x_ckgen.o

arm-none-eabi-gcc -c -mcpu=cortex-m0plus -mthumb -IInc -IDrivers/ATC_Driver/Inc -IDrivers/Device/Include -IDrivers/Device -IDrivers/Device/Include/CMSIS -IUser/Inc -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ac780x_spm.d" -Wa,-a,-ad,-alms=build/ac780x_spm.lst Drivers/ATC_Driver/Src/ac780x_spm.c -o build/ac780x_spm.o

arm-none-eabi-gcc -c -mcpu=cortex-m0plus -mthumb -IInc -IDrivers/ATC_Driver/Inc -IDrivers/Device/Include -IDrivers/Device -IDrivers/Device/Include/CMSIS -IUser/Inc -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/ac780x_uart.d" -Wa,-a,-ad,-alms=build/ac780x_uart.lst Drivers/ATC_Driver/Src/ac780x_uart.c -o build/ac780x_uart.o

arm-none-eabi-gcc -c -mcpu=cortex-m0plus -mthumb -IInc -IDrivers/ATC_Driver/Inc -IDrivers/Device/Include -IDrivers/Device -IDrivers/Device/Include/CMSIS -IUser/Inc -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/Uart.d" -Wa,-a,-ad,-alms=build/Uart.lst User/Src/Uart.c -o build/Uart.o

arm-none-eabi-gcc -x assembler-with-cpp -c -mcpu=cortex-m0plus -mthumb -IInc -IDrivers/ATC_Driver/Inc -IDrivers/Device/Include -IDrivers/Device -IDrivers/Device/Include/CMSIS -IUser/Inc -O0 -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"build/startup_AC7802x.d" startup_AC7802x.s -o build/startup_AC7802x.o

arm-none-eabi-gcc build/main.o build/AC7802x_irq_cb.o build/AC7802x_msp.o build/system_AC7802x.o build/ac780x_gpio.o build/ac780x_ckgen.o build/ac780x_spm.o build/ac780x_uart.o build/Uart.o build/startup_AC7802x.o -mcpu=cortex-m0plus -mthumb -specs=nano.specs -TAC78022MBQA_FLASH.ld -lc -lm -lnosys -Wl,-Map=build/AC7802_UART.map,--cref -Wl,--gc-sections -o build/AC7802_UART.elf

arm-none-eabi-size build/AC7802_UART.elf

text data bss dec hex filename

12016 12 2220 14248 37a8 build/AC7802_UART.elf

arm-none-eabi-objcopy -O ihex build/AC7802_UART.elf build/AC7802_UART.hex

arm-none-eabi-objcopy -O binary -S build/AC7802_UART.elf build/AC7802_UART.bin

5、输入下载命令:

lugl@lugl-virtual-machine:~/ac7802/AC7802_UART$ pyocd flash ./build/AC7802_UART.elf --target ac78022mbqa

0000426 I Loading /home/lugl/ac7802/AC7802_UART/build/AC7802_UART.elf [load_cmd]

[==================================================] 100%

0001139 I Erased 0 bytes (0 sectors), programmed 0 bytes (0 pages), skipped 12288 bytes (24 pages) at 16.84 kB/s [loader]

6、同时为了方便下载,我们在makefile后面增加 makefile flash命令实现下载:

flash:

pyocd flash ./build/AC7802_UART.elf --target ac78022mbqa

我们在执行make falsh后就可以实现下载功能了:

lugl@lugl-virtual-machine:~/ac7802/AC7802_UART$ make flash

pyocd flash ./build/AC7802_UART.elf --target ac78022mbqa

0000445 I Loading /home/lugl/ac7802/AC7802_UART/build/AC7802_UART.elf [load_cmd]

[==================================================] 100%

0001146 I Erased 0 bytes (0 sectors), programmed 0 bytes (0 pages), skipped 12288 bytes (24 pages) at 17.16 kB/s [loader]

l

7、实现效果:下载后,我们用typec线接到开发板的typec接口,打开串口助手,我们就可以实现不定义发送,同时AC7802把接收到的数据回显回来:

[20:21:10.657]发→◇AT1313123112123123

[20:21:10.661]收←◆AT1313123112123123

[20:47:13.157]发→◇AT13131231

[20:47:13.160]收←◆AT13131231

[20:47:22.561]发→◇你好

[20:47:22.563]收←◆你好

[20:47:30.890]发→◇你好 AC7802X

[20:47:30.893]收←◆你好 AC7802X

【总结】杰发的库函数做得非常好,给的示例也非常好,使得学习起来非常快捷。同时在linux环境下,用vscode也开发,也是非常之方便。体验了编程之快乐!

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • Linux
    +关注

    关注

    87

    文章

    11296

    浏览量

    209348
  • uart
    +关注

    关注

    22

    文章

    1235

    浏览量

    101356
  • DAC7802
    +关注

    关注

    0

    文章

    3

    浏览量

    6484
收藏 人收藏

    评论

    相关推荐

    FreeRTOS串口DMA收发不定长数据

    FreeRTOS例程,介绍串口DMA收发不定长数据
    的头像 发表于 09-26 09:08 4621次阅读
    FreeRTOS<b class='flag-5'>串口</b>DMA<b class='flag-5'>收发不定长</b>数据

    ubuntu编程——科技AC7802x串口控制LED灯

    串口命令控制AC7802x开发板上的LED灯
    的头像 发表于 06-04 16:46 3099次阅读
    ubuntu<b class='flag-5'>下</b>编程——<b class='flag-5'>杰</b><b class='flag-5'>发</b>科技AC<b class='flag-5'>7802x</b><b class='flag-5'>串口</b>控制LED灯

    FreeRTOS串口中断接收不定长的数据与二值信号量的使用

    FreeRTOS例程,使用串口中断接收不定长的数据,以及二值信号量的使用
    的头像 发表于 09-26 09:02 4196次阅读
    FreeRTOS<b class='flag-5'>串口</b>中断接收<b class='flag-5'>不定长</b>的数据与二值信号量的使用

    不定长数据接收的原理是什么?怎么实现串口数据的不定长接收?

    不定长数据接收的原理是什么?怎么实现串口数据的不定长接收?
    发表于 11-16 08:11

    怎样通过STM32的MDA和空闲中断实现串口不定长数据的收发

    怎样通过STM32的MDA和空闲中断实现串口不定长数据的收发呢?有哪些步骤?
    发表于 12-06 08:00

    怎样去完成STM32串口接收不定长数据hal库的实验

    怎样去完成STM32串口接收不定长数据hal库的实验呢?
    发表于 12-07 06:51

    请问串口DMA+环形缓冲区如何实现不定长度的数据收发

    请问串口DMA+环形缓冲区如何实现不定长度的数据收发
    发表于 12-08 06:13

    HAL库串口接收不定长数据的方法

    STM32单片机HAL库串口接收不定长数据HAL库串口接收不定长数据CubeMX配置过程代
    发表于 01-19 06:55

    HAL库的DMA+CobeMx方式不定长收发

    STM32L051双串口DMA方式不定长收发HAL库的DMA+CobeMx方式不定长收发Cu
    发表于 01-20 06:25

    stm32 串口接收不定长度数据及黏包处理 + 串口DMA接收

    1.不定长度数据 为什么会存在串口接收不定长度数据呢?首先,在通信双方进行数据传输的时候,由于不同的设备在实现控制,数据采样时,发送的数据指令字节数量存在着差异,就产生了串口接收
    发表于 12-23 19:09 27次下载
    stm32 <b class='flag-5'>串口</b>接收<b class='flag-5'>不定长</b>度数据及黏包处理 + <b class='flag-5'>串口</b>DMA接收

    STM32 DMA串口接收不定长数据

    STM32 DMA串口接收不定长数据
    发表于 12-24 18:50 40次下载
    STM32  DMA<b class='flag-5'>串口</b>接收<b class='flag-5'>不定长</b>数据

    STM32之串口DMA接收不定长数据

    目录STM32之串口DMA接收不定长数据引言DMA简介什么是DMA在STM32的DMA资源DMA接收数据判断数据接收完成接收完数据时处理程序实现STM32之串口DMA接收不定长数据引言
    发表于 12-24 19:03 30次下载
    STM32之<b class='flag-5'>串口</b>DMA接收<b class='flag-5'>不定长</b>数据

    科技AC7802x测评】开箱

    介绍科技AC7802x高可靠低功耗车规级MCU
    的头像 发表于 05-26 14:35 42.5w次阅读
    【<b class='flag-5'>杰</b><b class='flag-5'>发</b>科技AC<b class='flag-5'>7802x</b>测评】开箱

    STM32CubeMX之串口接收不定长数据

    基本串口通信通常只能接收到定长数据,无法稳定接收不定长数据,本章介绍利用STM32单片机的IDLE空闲中断,接收不定长数据。使能串口1的异步
    的头像 发表于 05-11 09:59 3369次阅读
    STM32CubeMX之<b class='flag-5'>串口</b>接收<b class='flag-5'>不定长</b>数据

    【代码分享】基于乐鑫ESP32的串口不定长数据接收方法

    【代码分享】基于乐鑫ESP32的串口不定长数据接收方法
    的头像 发表于 11-15 01:02 411次阅读
    【代码分享】基于乐鑫ESP32的<b class='flag-5'>串口</b><b class='flag-5'>不定长</b>数据接收方法