0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

體驗linux下杰發(fā)7802x開發(fā)串口不定長收發(fā)實驗

華仔的編程隨筆 ? 來源:華仔的編程隨筆 ? 作者:華仔的編程隨筆 ? 2023-06-04 15:37 ? 次閱讀

在這篇的基礎(chǔ)之上,我們今天學(xué)習(xí)使用AC7802的串口收發(fā)。

1、把原來的工程復(fù)制一份到新的文件夾,并重命名為AC7802_UART工程。

2、新建Uart.h、Uart.c,內(nèi)容如下:

#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; /* !< 串口發(fā)送長度變量 */

uint8_t g_txCnt = 0;

uint8_t g_rxBuf[RX_BUF_LEN] = {0}; /* !< 串口接收數(shù)組 */

/*!

  • @brief 串口回調(diào)函數(shù)
  • @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;

}

}

/*!< 發(fā)送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; /* ! 數(shù)據(jù)8bit */

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

uart_config.fifoByteEn = DISABLE;

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

uart_config.callBack = UART_Callback; /* ! 回調(diào)函數(shù)設(shè)置 */

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

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

UART_SetIdleFuncEn(UART1, ENABLE);

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

NVIC_SetPriority(UART1_IRQn, 3); /*! 串口中斷優(yōu)先級 */

NVIC_ClearPendingIRQ(UART1_IRQn);

NVIC_EnableIRQ(UART1_IRQn);

}

3、修改makefile內(nèi)容中的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結(jié)果如下:

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命令實現(xiàn)下載:

flash:

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

我們在執(zhí)行make falsh后就可以實現(xiàn)下載功能了:

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、實現(xiàn)效果:下載后,我們用typec線接到開發(fā)板的typec接口,打開串口助手,我們就可以實現(xiàn)不定義發(fā)送,同時AC7802把接收到的數(shù)據(jù)回顯回來:

[20:21:10.657]發(fā)→◇AT1313123112123123

[20:21:10.661]收←◆AT1313123112123123

[20:47:13.157]發(fā)→◇AT13131231

[20:47:13.160]收←◆AT13131231

[20:47:22.561]發(fā)→◇你好

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

[20:47:30.890]發(fā)→◇你好 AC7802X

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

【總結(jié)】杰發(fā)的庫函數(shù)做得非常好,給的示例也非常好,使得學(xué)習(xí)起來非??旖?。同時在linux環(huán)境下,用vscode也開發(fā),也是非常之方便。體驗了編程之快樂!

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • Linux
    +關(guān)注

    關(guān)注

    87

    文章

    11123

    瀏覽量

    207919
  • uart
    +關(guān)注

    關(guān)注

    22

    文章

    1199

    瀏覽量

    100830
  • DAC7802
    +關(guān)注

    關(guān)注

    0

    文章

    3

    瀏覽量

    6477
收藏 人收藏

    評論

    相關(guān)推薦

    FreeRTOS串口DMA收發(fā)不定長數(shù)據(jù)

    FreeRTOS例程,介紹串口DMA收發(fā)不定長數(shù)據(jù)
    的頭像 發(fā)表于 09-26 09:08 ?4251次閱讀
    FreeRTOS<b class='flag-5'>串口</b>DMA<b class='flag-5'>收發(fā)不定長</b>數(shù)據(jù)

    ubuntu編程——發(fā)科技AC7802x串口控制LED燈

    串口命令控制AC7802x開發(fā)板上的LED燈
    的頭像 發(fā)表于 06-04 16:46 ?2788次閱讀
    ubuntu<b class='flag-5'>下</b>編程——<b class='flag-5'>杰</b><b class='flag-5'>發(fā)</b>科技AC<b class='flag-5'>7802x</b><b class='flag-5'>串口</b>控制LED燈

    FreeRTOS串口中斷接收不定長的數(shù)據(jù)與二值信號量的使用

    FreeRTOS例程,使用串口中斷接收不定長的數(shù)據(jù),以及二值信號量的使用
    的頭像 發(fā)表于 09-26 09:02 ?3793次閱讀
    FreeRTOS<b class='flag-5'>串口</b>中斷接收<b class='flag-5'>不定長</b>的數(shù)據(jù)與二值信號量的使用

    不定長數(shù)據(jù)接收的原理是什么?怎么實現(xiàn)串口數(shù)據(jù)的不定長接收?

    不定長數(shù)據(jù)接收的原理是什么?怎么實現(xiàn)串口數(shù)據(jù)的不定長接收?
    發(fā)表于 11-16 08:11

    怎樣通過STM32的MDA和空閑中斷實現(xiàn)串口不定長數(shù)據(jù)的收發(fā)

    怎樣通過STM32的MDA和空閑中斷實現(xiàn)串口不定長數(shù)據(jù)的收發(fā)呢?有哪些步驟?
    發(fā)表于 12-06 08:00

    怎樣去完成STM32串口接收不定長數(shù)據(jù)hal庫的實驗

    怎樣去完成STM32串口接收不定長數(shù)據(jù)hal庫的實驗呢?
    發(fā)表于 12-07 06:51

    請問串口DMA+環(huán)形緩沖區(qū)如何實現(xiàn)不定長度的數(shù)據(jù)收發(fā)?

    請問串口DMA+環(huán)形緩沖區(qū)如何實現(xiàn)不定長度的數(shù)據(jù)收發(fā)?
    發(fā)表于 12-08 06:13

    HAL庫串口接收不定長數(shù)據(jù)的方法

    STM32單片機HAL庫串口接收不定長數(shù)據(jù)HAL庫串口接收不定長數(shù)據(jù)CubeMX配置過程代
    發(fā)表于 01-19 06:55

    HAL庫的DMA+CobeMx方式不定長收發(fā)

    STM32L051雙串口DMA方式不定長收發(fā)HAL庫的DMA+CobeMx方式不定長收發(fā)Cu
    發(fā)表于 01-20 06:25

    STM32串口接收不定長數(shù)據(jù)的程序免費下載

    本文檔的主要內(nèi)容詳細介紹的是STM32串口接收不定長數(shù)據(jù)的程序免費下載。
    發(fā)表于 08-26 08:00 ?47次下載
    STM32<b class='flag-5'>串口</b>接收<b class='flag-5'>不定長</b>數(shù)據(jù)的程序免費下載

    stm32 串口接收不定長度數(shù)據(jù)及黏包處理 + 串口DMA接收

    1.不定長度數(shù)據(jù) 為什么會存在串口接收不定長度數(shù)據(jù)呢?首先,在通信雙方進行數(shù)據(jù)傳輸?shù)臅r候,由于不同的設(shè)備在實現(xiàn)控制,數(shù)據(jù)采樣時,發(fā)送的數(shù)據(jù)指令字節(jié)數(shù)量存在著差異,就產(chǎn)生了串口接收
    發(fā)表于 12-23 19:09 ?26次下載
    stm32 <b class='flag-5'>串口</b>接收<b class='flag-5'>不定長</b>度數(shù)據(jù)及黏包處理 + <b class='flag-5'>串口</b>DMA接收

    STM32 DMA串口接收不定長數(shù)據(jù)

    STM32 DMA串口接收不定長數(shù)據(jù)
    發(fā)表于 12-24 18:50 ?40次下載
    STM32  DMA<b class='flag-5'>串口</b>接收<b class='flag-5'>不定長</b>數(shù)據(jù)

    STM32之串口DMA接收不定長數(shù)據(jù)

    目錄STM32之串口DMA接收不定長數(shù)據(jù)引言DMA簡介什么是DMA在STM32的DMA資源DMA接收數(shù)據(jù)判斷數(shù)據(jù)接收完成接收完數(shù)據(jù)時處理程序?qū)崿F(xiàn)STM32之串口DMA接收不定長數(shù)據(jù)引言
    發(fā)表于 12-24 19:03 ?30次下載
    STM32之<b class='flag-5'>串口</b>DMA接收<b class='flag-5'>不定長</b>數(shù)據(jù)

    發(fā)科技AC7802x測評】開箱

    介紹發(fā)科技AC7802x高可靠低功耗車規(guī)級MCU
    的頭像 發(fā)表于 05-26 14:35 ?42.5w次閱讀
    【<b class='flag-5'>杰</b><b class='flag-5'>發(fā)</b>科技AC<b class='flag-5'>7802x</b>測評】開箱

    STM32CubeMX之串口接收不定長數(shù)據(jù)

    基本串口通信通常只能接收到定長數(shù)據(jù),無法穩(wěn)定接收不定長數(shù)據(jù),本章介紹利用STM32單片機的IDLE空閑中斷,接收不定長數(shù)據(jù)。使能串口1的異步
    的頭像 發(fā)表于 05-11 09:59 ?2931次閱讀
    STM32CubeMX之<b class='flag-5'>串口</b>接收<b class='flag-5'>不定長</b>數(shù)據(jù)