找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2671|回復(fù): 0
收起左側(cè)

DMA控制M2M,M2P

[復(fù)制鏈接]
ID:327671 發(fā)表于 2019-11-21 20:22 | 顯示全部樓層 |閱讀模式
DAM控制器
內(nèi)存到內(nèi)存空間
1、在flash中定義好要傳輸?shù)臄?shù)據(jù),在SRAM中定義好用來接收flash數(shù)據(jù)的變量。
2、初始化DMA,主要配置DMA初始化結(jié)構(gòu)體。
3、編寫比較函數(shù)。
4、編寫main函數(shù)。
typedef struct
{
  uint32_t DMA_PeripheralBaseAddr; //外設(shè)地址   數(shù)據(jù)目標(biāo)地址

  uint32_t DMA_MemoryBaseAddr;     /*存儲地址   數(shù)據(jù)來源地址*/

  uint32_t DMA_DIR;                /*傳輸方向*/

  uint32_t DMA_BufferSize;         /*傳輸數(shù)目*/

  uint32_t DMA_PeripheralInc;      /*外設(shè)地址增量模式*/

  uint32_t DMA_MemoryInc;          /*存儲器地址增量模式*/

  uint32_t DMA_PeripheralDataSize; /*外設(shè)數(shù)據(jù)寬度*/

  uint32_t DMA_MemoryDataSize;     /*存儲器數(shù)據(jù)寬度*/

  uint32_t DMA_Mode;               /*模式選擇*/

  uint32_t DMA_Priority;           /*通道優(yōu)先級*/

  uint32_t DMA_M2M;                /*存儲器到存儲器模式*/
}DMA_InitTypeDef;
//DMA1_Channel6 初始化函數(shù)
//從FLASH傳送數(shù)據(jù)到SRAM
void DmaConfig(void)
{
    DMA_InitTypeDef DMA_InitStruct;
   
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
   
    DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)SRAM_SIZE;
    DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)FLASH_SIZE;
    DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;
    DMA_InitStruct.DMA_BufferSize = BUF_SIZE;
    DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Enable;
    DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
    DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
    DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
    DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
    DMA_InitStruct.DMA_Priority = DMA_Priority_Medium;
    DMA_InitStruct.DMA_M2M = DMA_M2M_Enable;
   
    DMA_Init(DMA1_Channel6, &DMA_InitStruct);
   
    DMA_ClearFlag(DMA1_FLAG_TC6);
    DMA_Cmd(DMA1_Channel6, ENABLE);
}


//從flash發(fā)送數(shù)據(jù)到USART
void PTOM_DmaConfig(void)
{
    DMA_InitTypeDef DMA_InitStruct;
   
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
   
    DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)USART1_BASE_DR;
    DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)SEND_USART;
    DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralDST;
    DMA_InitStruct.DMA_BufferSize = USART_BUF_SIZE;
    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_Medium;
    DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
   
    DMA_Init(DMA1_Channel4, &DMA_InitStruct);
   
    DMA_ClearFlag(DMA1_FLAG_TC4);
    DMA_Cmd(DMA1_Channel4, ENABLE);

}
//串口初始化,但不使能中斷
void Usart_Config(void)
    {
  //GPIO端口設(shè)置
  GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
     
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);    //使能USART1,GPIOA時鐘
  
    //USART1_TX   GPIOA.9
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;    //復(fù)用推挽輸出
  GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.9
   
  //USART1_RX      GPIOA.10初始化
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空輸入
  GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.10  
  
   //USART 初始化設(shè)置

    USART_InitStructure.USART_BaudRate = 115200;//串口波特率
    USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字長為8位數(shù)據(jù)格式
    USART_InitStructure.USART_StopBits = USART_StopBits_1;//一個停止位
    USART_InitStructure.USART_Parity = USART_Parity_No;//無奇偶校驗位
    USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//無硬件數(shù)據(jù)流控制
    USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;    //收發(fā)模式

  USART_Init(USART1, &USART_InitStructure); //初始化串口1
  USART_Cmd(USART1, ENABLE);                    //使能串口1

}
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表