STM32 串口采用DMA方式收发_if(buffer) memcpy((1)

收集整理了一份《2024年最新物联网嵌入式全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升的朋友。
img
img

如果你需要这些资料,可以戳这里获取

需要这些体系化资料的朋友,可以加我V获取:vip1024c (备注嵌入式)

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人

都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

DMA1: 
这里写图片描述

DMA2: 
这里写图片描述

2、DMA配置 
1)数据传输的目的地和来源 
这里写图片描述 
对应我的例子,就是送快递还是取快递。

2)定义DMA通道的DMA缓存的大小 
ps: 即货柜大小,能存多少个快件

3)外设地址寄存器递增与否 
这里写图片描述

4)内存地址寄存器递增与否 
这里写图片描述

5)设定了外设数据宽度 
这里写图片描述

6)设定了内存数据宽度 
这里写图片描述

7)设置了DMA的工作模式 

### STM32F103 UART DMA Data Transmission and Reception Tutorial #### Initialization of UART with DMA for Sending and Receiving For initializing the UART interface on an STM32F103 microcontroller to use Direct Memory Access (DMA) for both sending and receiving, several steps are necessary. The configuration involves setting up not only the UART but also configuring the DMA channels properly. The initialization function sets up UART4 for communication using DMA mode: ```c void UART4_DMA_Init(void){ // Configure UART4 parameters such as baud rate, word length, stop bits etc. // Enable clocks for UART4 and associated GPIOs // Initialize UART4 peripheral settings here... } ``` To start a DMA transfer specifically for transmitting data over UART4, one can utilize a similar approach shown below: ```c void UART4_DMA_Begin_Send(uint8_t *send_buffer , uint16_t nSendBytes) { if (nSendBytes < UART4_DMA_TX_BUFFER_MAX_LENGTH) { memcpy(UART4_DMA_TX_Buffer , send_buffer , nSendBytes); DMA_Cmd(DMA2_Channel5 , DISABLE); // Disable DMA channel before reconfiguration DMA_SetCurrDataCounter(DMA2_Channel5 , nSendBytes); // Set number of bytes to be transferred DMA_Cmd(DMA2_Channel5 , ENABLE); // Start DMA operation after setup is complete } }[^1] ``` In this context, `UART4_DMA_TX_BUFFER_MAX_LENGTH` defines the maximum size that can fit into the buffer used by DMA for transmission purposes. Before initiating any new transfers via DMA, it's important to ensure previous operations have completed successfully. When dealing with reception through DMA, ensuring proper handling includes defining buffers where incoming characters will reside until processed further within application logic. For instance, ```c uint8_t UART4_RX_Buffer[RECEIVE_BUFFER_SIZE]; volatile uint16_t rx_index = 0; // Function called when DMA completes reading from UART RX line void UART4_DMA_Receive_Complete_Callback() { // Process received data stored in UART4_RX_Buffer starting at index 'rx_index' } // Configuration needed for enabling DMA receive functionality void UART4_DMA_Rx_Configuration(){ // Setup DMA stream/channel dedicated for UART4 Rx direction including specifying source address, // destination address pointing towards UART4_RX_Buffer variable defined earlier plus other attributes like priority level etc. } ``` It’s crucial during development phases involving DMA-based communications to verify configurations related to interrupt priorities since these affect how quickly responses occur once events trigger them. Additionally, confirming correct wiring between hardware components plays a significant role too. Regarding software preparation, make sure relevant HAL libraries or equivalent low-level drivers supporting your chosen series of MCUs get included correctly inside project files so functions mentioned above work seamlessly together without issues arising due to missing definitions or declarations.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值