标题:
stm32 DMA实验程序
[打印本页]
作者:
柯南240
时间:
2019-3-9 08:05
标题:
stm32 DMA实验程序
stm32DMA数据传输实验
单片机源程序如下:
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "LCD.h"
/* Private functions ---------------------------------------------------------*/
u8 buffer[100];
void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE, ENABLE);
//USART的TX和RX管脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA , &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//LED灯
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void USART_Config(void)
{
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
//配置USART状态
USART_InitStructure.USART_BaudRate = 9600;
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(USART1 , &USART_InitStructure);
USART_Cmd(USART1 , ENABLE);
}
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStruct;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_InitStruct.DMA_PeripheralBaseAddr=0x40013804;
DMA_InitStruct.DMA_MemoryBaseAddr =(u32)buffer;
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStruct.DMA_BufferSize = 100;
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStruct.DMA_Mode = DMA_Mode_Normal;
DMA_InitStruct.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel4, &DMA_InitStruct);
}
void putData(u8 ch)
{
USART_SendData(USART1,ch);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
}
void Delay(unsigned k)
{
unsigned j;
for(j=0;j<=k;j++);
}
void Led1(void)
{
GPIO_ResetBits(GPIOC, GPIO_Pin_6);
Delay(0xfffff);
GPIO_SetBits(GPIOC, GPIO_Pin_6);
}
void Led4(void)
{
GPIO_SetBits(GPIOC, GPIO_Pin_9);
Delay(0xfffff);
GPIO_ResetBits(GPIOC, GPIO_Pin_9);
}
int main(void)
{
unsigned i,j=0;
unsigned char TxBuf1[100] = " welcome to yubing's home!";
#ifdef DEBUG
debug();
#endif
SystemInit();
lcd_init ();
GPIO_Config();
USART_Config();
DMA_Config();
lcd_clear ();
lcd_putCustomChar();
lcd_print("is a pig");
for(i=0;i<=100;i++)
{
buffer[j]=TxBuf1[i];
j++;
}
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);
DMA_Cmd(DMA1_Channel4, ENABLE);
while(DMA_GetFlagStatus(DMA1_FLAG_TC4)==RESET)
{
Led4();
}
while(1)
{
}
}
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
复制代码
所有资料51hei提供下载:
project8_DMA.7z
(174.72 KB, 下载次数: 8)
2019-3-10 21:17 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
admin
时间:
2019-3-10 21:18
本帖需要重新编辑补全电路原理图,源码,详细说明与图片即可获得100+黑币(帖子下方有编辑按钮)
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1