资源简介
STM32F4 串口(DMA发送接收方式)代码例程
STM32F4 DMA收发 经过稳定测试
初始化后直接用
代码片段和文件信息
#include “stm32f4xx.h“
#include “UART1.h“
#include “String.h“
#define BUFFER_SIZE1 50
static DMA_InitTypeDef DMA_InitStructureTx;
static DMA_InitTypeDef DMA_InitStructureRx;
static char TxBuffer[BUFFER_SIZE1];
static char RxBuffer[BUFFER_SIZE1];
__IO u16 RxCount = 0;
void USART1_Init(void) //串口初始化
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_DMA2 ENABLE);
GPIO_PinAFConfig(GPIOA GPIO_PinSource9 GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA GPIO_PinSource10 GPIO_AF_USART1);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOA &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1 &USART_InitStructure);
USART_DMACmd(USART1 USART_DMAReq_Tx | USART_DMAReq_Rx ENABLE);
DMA_InitStructureTx.DMA_BufferSize = BUFFER_SIZE1 ;
DMA_InitStructureTx.DMA_FIFOMode = DMA_FIFOMode_Disable ;
DMA_InitStructureTx.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ;
DMA_InitStructureTx.DMA_MemoryBurst = DMA_MemoryBurst_Single ;
DMA_InitStructureTx.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructureTx.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructureTx.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructureTx.DMA_PeripheralbaseAddr =(uint32_t) (&(USART1->DR)) ;
DMA_InitStructureTx.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_InitStructureTx.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructureTx.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructureTx.DMA_Priority = DMA_Priority_High;
/* Configure TX DMA */
DMA_InitStructureTx.DMA_Channel = DMA_Channel_4 ;
DMA_InitStructureTx.DMA_DIR = DMA_DIR_MemoryToPeripheral ;
DMA_InitStructureTx.DMA_Memory0baseAddr =(uint32_t)TxBuffer ;
DMA_Init(DMA2_Stream7&DMA_InitStructureTx);
DMA_ITConfig(DMA2_Stream7 DMA_IT_TC ENABLE);
DMA_InitStructureRx.DMA_BufferSize = BUFFER_SIZE1 ;
DMA_InitStructureRx.DMA_FIFOMode = DMA_FIFOMode_Disable ;
DMA_InitStructureRx.DMA_FIFOThreshold = DMA_FIFOThreshold_1QuarterFull ;
DMA_InitStructureRx.DMA_MemoryBurst = DMA_Memor
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 205 2015-08-12 18:58 UART1.h
文件 5449 2015-08-12 19:31 UART1.c
- 上一篇:原版官方稳定版本Lwip1.4.1
- 下一篇:基于数据库的登陆系统
相关资源
- 基于STM32F4x9的LCD显示
- stm32的DAC播放音乐文件
- SecureCRT 非常好用的串口工具
- 串口调试工具 SecureCRT
- 串口发送小工具
- 基于STM32的深海钻机甲板控制系统
- SCI串口中断接收发送例程
- STM32F103 USART+DMA
- DMA+stm32 407.zip
- 4_USART串口通信(空闲中断+DMA.zip
- stm32f105-usart-DMA收发demo
- STM32F042F6P6 Uart12DMA;发送中断接收
- 串口模拟器支持win10
- ch352 pci转并口串口卡驱动(WinChipHea
- pci/pcie打印卡串口/并口卡驱动
- stm32F4+w5300
- usb转 串口驱动 ch340 PL2303 win10 可用
- 推荐给大家一个非常好用的串口工具
- USB-Serial-Controller_虚拟串口.rar
- free-serial-port-monitor_(串口监控调试)
- TD-SCDMA网络测试仪中E1数据采集卡的驱
- TD-SCDMA测试仪中Iub接口CDR的合成方案
- Delphi7串口程序(使用SPComm控件).ra
- 安捷伦CDMA2000测试解决方案
- FreeModbus_Slave+STM32F407+USART2代码亲测可
- Pix4Dmapper4.4.10中文破解版带注册机网盘
- Pix4Dmapper4.4.10中文破解
- Pix4Dmapper教程
- USB Serial Port win7 64/32 驱动后缀丢失,
- STC11F04单片机串口终端程序
评论
共有 条评论