你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32笔记(四)DMA、USART的演示

[复制链接]
私奔 发布时间:2009-1-4 14:30
阅读主题, 点击返回1楼
收藏 评论44 发布时间:2009-1-4 14:30
44个回答
birdcq 回答时间:2011-5-13 14:35:18

RE:STM32笔记(四)DMA、USART的演示

好东西 下来看看 l
cocoasuny 回答时间:2011-11-4 14:15:28

RE:STM32笔记(四)DMA、USART的演示

谢谢,第一次使用DMA!
yfwang555 回答时间:2011-12-11 11:25:59

回复:STM32笔记(四)DMA、USART的演示

hfgggggggggggggggggggggggggggggkjttttttttttttttttttttttttttttttttttttttttttttttty
piaopiao123 回答时间:2011-12-20 09:28:40

RE:STM32笔记(四)DMA、USART的演示

各位大虾,帮忙看看,我的DMA串口可以发送,但是不能接收,请问可能会是什么问题呢?谢谢!
#define TxBufferSize  16
#define RxBufferSize  16
uint8_t TxBuffer[TxBufferSize] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F};
uint8_t RxBuffer[RxBufferSize];
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Channel7);  
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40004404;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)TxBuffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = TxBufferSize;
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_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel7, &DMA_InitStructure);
DMA_DeInit(DMA1_Channel6);  
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40004404;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)RxBuffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = RxBufferSize;
DMA_Init(DMA1_Channel6, &DMA_InitStructure);
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_DeInit(USART2);
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_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART2,&USART_InitStructure);
}
void GPIO_Board_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  /* DMA1 Periph clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
  /* GPIO Periph clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO , ENABLE);
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 , ENABLE);
  /* Configure GPIOA  Out mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_11 | GPIO_Pin_12;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  /* Configure GPIOB  Out mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_5 | GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  /* Configure GPIOC  Out mode */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  /* Configure USART2 Rx as input floating */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  /* Configure USART2 Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
}
int main(void)
{
while(1)
{
if(DMA_GetFlagStatus(DMA1_FLAG_TC6) == SET)
    {
         DMA_ClearFlag(DMA1_FLAG_TC6);
     DMA_Cmd(DMA1_Channel6, DISABLE);
     DMA_SetCurrDataCounter(DMA1_Channel6,RxBufferSize);
         GPIO_SetBits(GPIOC,GPIO_Pin_8);
     delay(500);
     GPIO_ResetBits(GPIOC,GPIO_Pin_8 );
     delay(500);
   }
else
{
GPIO_SetBits(GPIOC,GPIO_Pin_9);
     delay(500);
     GPIO_ResetBits(GPIOC,GPIO_Pin_9 );
     delay(500);
}
}
}
anyway76 回答时间:2011-12-23 11:09:42

回复:STM32笔记(四)DMA、USART的演示

正在接触STM32,多谢分享
njlhp123 回答时间:2011-12-23 18:35:09

回复:STM32笔记(四)DMA、USART的演示

回复第 3 楼 于2009-01-05 04:18:28发表:
原帖由私奔于2009-01-04 14:30发表:
  这里有个小小的例子,来演示DMA模块与系统程序并行工作。
  用串口以低波特率发送一个10K的数据,花费近10s时间,此时按照以往方法,CPU要不断等待数据发送、送数据;或者送数据、进中断、送数据,处理起来比较消耗时间。
  使用了DMA功能以后,用户程序中只需配置好DMA,开启传输后,再也不需要操心,10K数据完成后会有标志位或中断产生,期间可以做任何想做的事,非常方便。
  这个是相应的代码例子,基于STM32F103VBT6


/******************************************************************************
* 本文件实现串口发送功能(通过重构putchar函数,调用printf;或者USART_SendData()
* 这里是一个用串口实现大量数据传输的例子,使用了DMA模块进行内存到USART的传输
* 每当USART的发送缓冲区空时,USART模块产生一个DMA事件,
* 此时DMA模块响应该事件,自动从预先定义好的发送缓冲区中拿出下一个字节送给USART
* 整个过程无需用户程序干预,用户只需启动DMA传输传输即可
* 在仿真器调试时,可以在数据传输过程中暂停运行,此时DMA模块并没有停止
* 串口依然发送,表明DMA传输是一个独立的过程。
* 同时开启接收中断,在串口中断中将数据存入缓冲区,在main主循环中处理
* 作者:jjldc(九九)
* 代码硬件基于万利199元的EK-STM32F开发板,CPU=STM32F103VBT6
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
#include "stdio.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define USART1_DR_Base  0x40013804

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
#define SENDBUFF_SIZE   10240
vu8 SendBuff[SENDBUFF_SIZE];
vu8 RecvBuff[10];
vu8 recv_ptr;

/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void DMA_Configuration(void);
void USART1_Configuration(void);

int fputc(int ch, FILE *f);
void Delay(void);

/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{
    u16 i;
#ifdef DEBUG
    debug();
#endif
    recv_ptr = 0;
   
    RCC_Configuration();
    GPIO_Configuration();
    NVIC_Configuration();
    DMA_Configuration();
    USART1_Configuration();
   
    printf("\r\nSystem Start...\r\n");
    printf("Initialling SendBuff... \r\n");
    for(i=0;i    {
        SendBuff = i&0xff;
    }
    printf("Initial success!\r\nWaiting for transmission...\r\n");
    //发送去数据已经准备好,按下按键即开始传输
    while(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_3));
   
    printf("Start DMA transmission!\r\n");
   
    //这里是开始DMA传输前的一些准备工作,将USART1模块设置成DMA方式工作
    USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
    //开始一次DMA传输!
    DMA_Cmd(DMA1_Channel4, ENABLE);
   
    //等待DMA传输完成,此时我们来做另外一些事,点灯
    //实际应用中,传输数据期间,可以执行另外的任务
    while(DMA_GetFlagStatus(DMA1_FLAG_TC4) == RESET)
    {
        LED_1_REV;      //LED翻转
        Delay();        //浪费时间
    }
    //DMA传输结束后,自动关闭了DMA通道,而无需手动关闭
    //下面的语句被注释
    //DMA_Cmd(DMA1_Channel4, DISABLE);
   
    printf("\r\nDMA transmission successful!\r\n");

   
    /* Infinite loop */
    while (1)
    {
    }
}

/*******************************************************************************
* Function Name  : 重定义系统putchar函数int fputc(int ch, FILE *f)
* Description    : 串口发一个字节
* Input          : int ch, FILE *f
* Output         :
* Return         : int ch
* 这个是使用printf的关键
*******************************************************************************/
int fputc(int ch, FILE *f)
{
    //USART_SendData(USART1, (u8) ch);
    USART1->DR = (u8) ch;
   
    /* Loop until the end of transmission */
    while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
    {
    }

    return ch;
}

/*******************************************************************************
* Function Name  : Delay
* Description    : 延时函数
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Delay(void)
{
    u32 i;
    for(i=0;i外设
    //每次传输位:8bit
    //传输大小DMA_BufferSize=SENDBUFF_SIZE
    //地址自增模式:外设地址不增,内存地址自增1
    //DMA模式:一次传输,非循环
    //优先级:中
    DMA_DeInit(DMA1_Channel4);
    DMA_InitStructure.DMA_PeripheralBaseAddr = USART1_DR_Base;
    DMA_InitStructure.DMA_MemoryBaseAddr = (u32)SendBuff;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
    DMA_InitStructure.DMA_BufferSize = SENDBUFF_SIZE;
    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_Normal;
    DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
    DMA_Init(DMA1_Channel4, &DMA_InitStructure);
}
 
谢谢分享
zhixiangyuhui 回答时间:2012-3-6 22:34:06

RE:STM32笔记(四)DMA、USART的演示

棒~
lxllf520-225827 回答时间:2012-3-16 20:56:10

回复:STM32笔记(四)DMA、USART的演示

在哪里下载??
你好-364167 回答时间:2012-8-16 19:55:58

回复:STM32笔记(四)DMA、USART的演示

不错呀 就是要学 这个程序呀
longzhaocy 回答时间:2012-12-19 16:45:33

回复:STM32笔记(四)DMA、USART的演示

不错,正需要,谢谢共享。。
jensenhero 回答时间:2012-12-24 15:50:32

回复:STM32笔记(四)DMA、USART的演示

不知道为什么,编译没有通过,貌似还得修改
jensenhero 回答时间:2012-12-24 15:50:35

回复:STM32笔记(四)DMA、USART的演示

不知道为什么,编译没有通过,貌似还得修改
suhetao-306309 回答时间:2013-4-9 21:10:54

回复:STM32笔记(四)DMA、USART的演示

学习了。感谢楼主的无私奉献
liaodata 回答时间:2013-9-9 19:36:31

回复:STM32笔记(四)DMA、USART的演示

 我需要参考之 写在f4上~~
Rodriguez 回答时间:2013-9-16 16:26:24

回复:STM32笔记(四)DMA、USART的演示

好同志啊,有没有F0的对应例程啊
123

所属标签

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版