这是以前学32的时候写的,那时候学了32之后感觉32真是太强大了,比51强的没影。关于dma网上有许多的资料,亲们搜搜,这里只贴代码了,其实我也想详详细细地叙述一番,但是自己本身打字就慢,还有好多事情要做!代码是我亲自都在板子上测试过的,,当然粘贴/复制过去可能也不会尽如人意,知识这东西总是有许多道不清说不明的东西在里头,往往总是不经一番彻骨寒,哪得梅花扑鼻香。推荐一本书吧!这是野火出的。(是为了凑够150个字,否则不让提交)

这本书自从在图书馆借来就从来没有再放回去,总是在续借。像是在打广告了

#include <stm32f10x.h>
#include "usart1.h"
#include "qq1.h"
#include "GPIO.h" extern uint8_t SendBuff[SENDBUFF_SIZE]; uint16_t i;
int main()
{
USART1_Config();
DMA_Config();
GPIOinit(); for(i= ; i<SENDBUFF_SIZE ; i++)
{
SendBuff[i] = 0xdd;
}
USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE); GPIO_Write(GPIOB,0xffff); //将GPIOB 16个端口全部置为高电 while();
}
/* 其他函数里 USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);     */
#include "usart1.h" uint8_t SendBuff[SENDBUFF_SIZE]; /*
* 函数名:DMA_Config
* 描述 :DMA 串口的初始化配置
* 输入 :无
* 输出 : 无
* 调用 :外部调用
*/
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //开启DMA时钟
NVIC_Config(); //配置DMA中断 /*设置DMA源:内存地址&串口数据寄存器地址*/
DMA_InitStructure.DMA_PeripheralBaseAddr = USART1_DR_Base; /*内存地址(要传输的变量的指针)*/
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)SendBuff; /*方向:从内存到外设*/
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; /*传输大小DMA_BufferSize=SENDBUFF_SIZE*/
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; /*内存数据单位 8bit*/
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; /*DMA模式:一次传输,循环*/
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal ; /*优先级:中*/
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; /*禁止内存到内存的传输 */
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; /*配置DMA1的4通道*/
DMA_Init(DMA1_Channel4, &DMA_InitStructure); DMA_Cmd (DMA1_Channel4,ENABLE); //使能DMA
DMA_ITConfig(DMA1_Channel4,DMA_IT_TC,ENABLE); //配置DMA发送完成后产生中断 }
/*
* 函数名:NVIC_Config
* 描述 :DMA 中断配置
* 输入 :无
* 输出 : 无
* 调用 :外部调用
*/
static void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure; /* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); /* 配置P[A|B|C|D|E]0为中断源 */
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = ;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = ;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
#ifndef __USART1_H
#define __USART1_H #include "stm32f10x.h" #define USART1_DR_Base 0x40013804
#define SENDBUFF_SIZE 5000 void DMA_Config(void);
static void NVIC_Config(void); #endif /* __USART1_H */
#include "qq1.h"

/*
* 函数名:USART1_Config
* 描述 :USART1 GPIO 配置,工作模式配置。115200 8-N-1
* 输入 :无
* 输出 : 无
* 调用 :外部调用
*/
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure; /* config USART1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE); /* USART1 GPIO config */
/* Configure USART1 Tx (PA.09) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure); /* USART1 mode config */
USART_InitStructure.USART_BaudRate = ;
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_Cmd(USART1, ENABLE);
}
#ifndef __QQ1_H
#define __QQ1_H #include <stm32f10x.h> void USART1_Config(void); #endif
#include"GPIO.h"

void GPIOinit(void)
{ GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; //所有GPIO为同一类型端口
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //输出的最大频率为50HZ GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化GPIOB端口 }
#ifndef __GPIO_H
#define __GPIO_H #include "stm32f10x.h" void GPIOinit(void); #endif
#include "stm32f10x_it.h"

void DMA1_Channel4_IRQHandler(void)
{ if(DMA_GetFlagStatus(DMA1_FLAG_TC4)==SET)
{ GPIOB ->BRR = GPIO_Pin_All; DMA_ClearFlag(DMA1_FLAG_TC4); }
}

最新文章

  1. JavaScript判断变量值简单的方法
  2. OpenLDAP,一登录系统就修改密码
  3. jquery noConflict详解
  4. Ubuntu自定义服务
  5. Docker run命令详解 转
  6. HDU1028Ignatius and the Princess III(母函数)
  7. wzplayer2 for windows ActiveX 试用地址
  8. MSBuild 教程(2)
  9. hdu 4496 D-City(并查集)
  10. JAVA设计模式:代理模式&amp;&amp; 装饰模式区别
  11. Java中excel与对象的互相转换的通用工具类编写与使用(基于apache-poi-ooxml)
  12. Mego(04) - Mego入门
  13. Fuck me
  14. Word中使用宏处理表格内容 小记
  15. tensorflow学习之(四)使用placeholder 传入值
  16. p2 弹簧
  17. python学习笔记-练手实例
  18. SpringInAction-- 配置Profile Bean
  19. Linux下服务器搭建
  20. Jenkins +JUnit

热门文章

  1. (1-2)line-height的各类属性值
  2. openCV 扩图
  3. View的measure机制
  4. describe命令
  5. 有道云笔记 markdown 本地资源图片 粘贴到word居然粘贴不过去 资源名不能有汉子
  6. 基于纤程(Fiber)实现C++异步编程库(一):原理及示例
  7. Loadrunner打开VU时候报错Critical error(cannot use Exceptiondialog)
  8. .NET(C#)使用Serialize、Deserialize序列和反序列化XML文档
  9. js拼接table查询信息部分
  10. python模拟自动登录网站(urllib2)