STM32之DMA_USART部分总结

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

USART_InitStructure.USART_BaudRate =115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
}
/*************************************************************
* Function Name : UASRT_Configuration
* Description : UASRT 的参数配置
* Input
: None
* Output
: None
/************************************************************
* Function Name : main
* Description : Main program
* Input
: None
* Output
: None
* Return
: None
=
DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst
=
DMA_PeripheralBurst_Single;
至此,DMA 的参数配置基本完成
三、例程
为了更好的熟悉 DMA 的工作机制,下面就一个比较完整地应用 DMA_USART 传输数据的实例(基于 STM32F407 discover 板子),其功 能为将一个数组里的一组数以 DMA 的方式通过串口发到上位机上并
通过串口助手查看串口接受到的数据,并以十六进制显示。
* Return
: None
**************************************************************/
void USART_Configuration(void)
{
/*--------USART3 的各个参数的配置-----------*/
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
9)、配置外设地址是否增加
DMA_InitStructure.DMA_PeripheralInc
=
DMA_PeripheralInc_Disable;
10)、配置内存地址是否增加
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
11)、 配置数据宽度
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/***** Enable DMA1 clock *****/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
/* Includes ----------------------------------*/
#include "stdio.h"
#include "stm32f4xx.h"
#include "stm324xg_eval.h"
/*--------------定义 USART3 的基地址------------*/
DMA_Init(DMAx_Streamx, &DMA_InitStructure);
15)、使能发送完成中断
DMA_ITConfig(DMAx_Streamx, DMA_IT_TC, ENABLE);
ቤተ መጻሕፍቲ ባይዱ
16)、使能 DMAx_Streamx
DMA_Cmd(DMAx_Streamx, ENABLE);
* Function Name : DMA_Configuration
* Description : Configures the DMA.
* Input
: None
* Output
: None
* Return
: None
**************************************************************/
二、DMA 工作机制
DMA 的参数配置一般步骤: 1)、定义 DMA 结构体 DMA_InitTypeDef DMA_InitStructure; 2)、使能对应DMA模块时钟 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMAx, ENABLE); 3)、DMAx 流的配置
STM_EVAL_LEDOn(LED1);
DMA_Configuration();
/* Turn LED2 on: start of EVAL_COM1 (USART3) configuration */
STM_EVAL_LEDOn(LED2);
USART_Configuration();
/*-------Turn LED3 on: ,start of Transfer and interrupt stop------*/
13)、配置 DMA 的传输优先级
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
14)、配置 FIFO 模式
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold
void Delay(__IO uint32_t nCount);
static void SysTickConfig(void);
/*-------------- DMA 传输内容-------------------*/
Uint16_t SendBuff[10]={0,1,2,3,4,5,6,7,8,9};
{
USART_DMACmd(EVAL_COM1, USART_DMAReq_Tx, DISABLE);
DMA_ClearITPendingBit(DMA1_Stream3,DMA_IT_TCIF3);
}
/* -----Turn LED6 on: Transfer correct ------*/
STM_EVAL_LEDOn(LED4);
#define USART3_DR_ADDRESS ((uint32_t)0x40004804)
/*--------------函数的声明-------------------*/
void USART_Configuration(void);
void DMA_Configuration(void);
STM_EVAL_COMInit(COM1, &USART_InitStructure);
/* Enable USART */
USART_Cmd(COM1, ENABLE);
}
/*************************************************************
STM_EVAL_LEDOn(LED3);
USART_DMACmd(EVAL_COM1, USART_DMAReq_Tx, ENABLE);
/*-----------Delay 0xFFFF------------*/ SysTickConfig(); Delay(0xFFFFFFFF); while(DMA_GetITStatus(DMA1_Stream3,DMA_IT_TCIF3)!= RESET)
R_ADDRESS;
6)、内存地址
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)SendBuff;
7)、数据传输方向
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
8)、数据大小
DMA_InitStructure.DMA_BufferSize = x;
STM32 之 DMA_USART 部分总结
—杨龙(11.08) 一、概述
DMA(Direct Memory Access)直接内存访问。简单的说就是 不经过 CPU 就可以直接访问内存,在以 DMA 的方式进行数据通信时, CPU 可以继续干其他的工作。DMA 数据传输方式是 STM32 系列芯片的 主要通信方式之一,在现实生活中有着非常广泛的应用。由于 DMA 通 信方式本身所独有的通信特点和 DMA 与 USART 等其他通信方式相结合 的工作模式,不仅能够使得单片机的通信速度得到很大的提高,而且 可以大大增加单片机的 CPU 的工作效率,降低单片机的功耗。掌握 DMA 的通信方式和特点,一方面有助于深入学习 STM32 系列芯片的内 存与内存、内存与外设、外设与内存之间的通信原理,另一方面能够 在后续学习 STM32 的 USB 等其他通信方式时有个很好的理解。由于之 前已经对串口通信部分做了详细的总结,所以这篇文档只对 DMA 的工 作机制做以总结,USART 部分就不在这里详细赘述。
DMA_InitStructure.DMA_PeripheralDataSize=
DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize
=
DMA_MemoryDataSize_Byte;
12)、配置 DMA 传输模式
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular ;
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_EXTI);
/* Turn LED1 on: start of configuration DMA1 Stream3 channel4 */
DMA_DeInit(DMAx_Streamx);
4)、DMAx 通道 x 配置
DMA_InitStructure.DMA_Channel = DMA_Channel_x;
5)、外设地址
DMA_InitStructure.DMA_PeripheralBaseAddr=(uint32_t)USARTx_D
/* DMA1 Stream3 channel4 configuration */
DMA_DeInit(DMA1_Stream3); DMA_InitStructure.DMA_Channel = DMA_Channel_4; DMA_InitStructure.DMA_PeripheralBaseAddr=(uint32_t)USART3_DR_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)SendBuff; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; DMA_InitStructure.DMA_BufferSize = 20; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular ; DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable; DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA1_Stream3, &DMA_InitStructure);
*************************************************************/
int main(void)
{
/* Configure LEDs to monitor program status */
STM_EVAL_LEDInit(LED1);
STM_EVAL_LEDInit(LED2);
相关文档
最新文档