找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 784|回复: 1
打印 上一主题 下一主题
收起左侧

stm32 DMA实验程序

[复制链接]
跳转到指定楼层
楼主
ID:336853 发表于 2019-3-9 08:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
stm32DMA数据传输实验

单片机源程序如下:
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f10x.h"
  3. #include "LCD.h"
  4. /* Private functions ---------------------------------------------------------*/
  5. u8 buffer[100];

  6. void GPIO_Config(void)
  7. {
  8.     GPIO_InitTypeDef GPIO_InitStructure;
  9.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE, ENABLE);
  10. //USART的TX和RX管脚
  11.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  12.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  13.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  14.     GPIO_Init(GPIOA , &GPIO_InitStructure);
  15.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  16.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  17.     GPIO_Init(GPIOA, &GPIO_InitStructure);

  18. //LED灯
  19.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9 ;
  20.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  21.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;       
  22.     GPIO_Init(GPIOC, &GPIO_InitStructure);

  23. }

  24. void USART_Config(void)
  25. {
  26.     USART_InitTypeDef USART_InitStructure;
  27.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  28. //配置USART状态                                                     
  29.     USART_InitStructure.USART_BaudRate = 9600;
  30.     USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  31.     USART_InitStructure.USART_StopBits = USART_StopBits_1;
  32.     USART_InitStructure.USART_Parity = USART_Parity_No;
  33.     USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  34.     USART_InitStructure.USART_HardwareFlowControl =
  35.     USART_HardwareFlowControl_None;
  36.     USART_Init(USART1 , &USART_InitStructure);
  37.     USART_Cmd(USART1 , ENABLE);
  38. }


  39. void DMA_Config(void)
  40. {       
  41.     DMA_InitTypeDef DMA_InitStruct;
  42.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
  43.         DMA_InitStruct.DMA_PeripheralBaseAddr=0x40013804;
  44.         DMA_InitStruct.DMA_MemoryBaseAddr =(u32)buffer;
  45.         DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralDST;
  46.         DMA_InitStruct.DMA_BufferSize = 100;
  47.         DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  48.         DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
  49.         DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
  50.         DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
  51.         DMA_InitStruct.DMA_Mode = DMA_Mode_Normal;
  52.         DMA_InitStruct.DMA_Priority = DMA_Priority_VeryHigh;
  53.     DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
  54.     DMA_Init(DMA1_Channel4, &DMA_InitStruct);
  55. }


  56. void putData(u8 ch)
  57. {
  58.     USART_SendData(USART1,ch);
  59.     while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET);
  60. }



  61. void Delay(unsigned k)
  62. {
  63.         unsigned j;
  64.         for(j=0;j<=k;j++);
  65. }

  66. void Led1(void)
  67. {
  68.     GPIO_ResetBits(GPIOC, GPIO_Pin_6);
  69.         Delay(0xfffff);
  70.         GPIO_SetBits(GPIOC, GPIO_Pin_6);
  71. }

  72. void Led4(void)
  73. {
  74.     GPIO_SetBits(GPIOC, GPIO_Pin_9);
  75.         Delay(0xfffff);
  76.         GPIO_ResetBits(GPIOC, GPIO_Pin_9);
  77. }


  78. int main(void)
  79. {
  80.     unsigned i,j=0;
  81.     unsigned char TxBuf1[100] = " welcome to yubing's home!";
  82.     #ifdef DEBUG
  83.     debug();                                                                       
  84.     #endif
  85.     SystemInit();
  86.         lcd_init  ();
  87.     GPIO_Config();
  88.         USART_Config();
  89.         DMA_Config();
  90.         lcd_clear ();
  91.         lcd_putCustomChar();
  92.         lcd_print("is a pig");
  93.     for(i=0;i<=100;i++)
  94.          {
  95.     buffer[j]=TxBuf1[i];
  96.         j++;
  97.      }
  98.         USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);
  99.         DMA_Cmd(DMA1_Channel4, ENABLE);
  100.         while(DMA_GetFlagStatus(DMA1_FLAG_TC4)==RESET)
  101.         {
  102.         Led4();
  103.         }
  104. while(1)
  105.   {


  106.   }
  107. }


  108. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
复制代码

所有资料51hei提供下载:
project8_DMA.7z (174.72 KB, 下载次数: 8)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1 发表于 2019-3-10 21:18 | 只看该作者
本帖需要重新编辑补全电路原理图,源码,详细说明与图片即可获得100+黑币(帖子下方有编辑按钮)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表