相关代码 这里使用的是SPI1 SPI_DMA配置
/*******************************************************************************
* Function Name : SPI1_DMA_Configuration
* Description : 配置SPI1_RX的DMA通道2,SPI1_TX的DMA通道3
* Input : None
* Output : None
* Return : None
* Attention :
*******************************************************************************/
void SPI1_DMA_Configuration( void )
{
DMA_InitTypeDef DMA_InitStructure;
/* DMA1 Channel2 (triggered by SPI1 Rx event) Config */
DMA_DeInit(DMA1_Channel2);
DMA_InitStructure.DMA_PeripheralBaseAddr = SPI1_DR_Addr; //设置 SPI1 发送外设(0x4001300C) 地址(目的地址)
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SPI1_RX_Buff; //设置 SRAM 存储地址(目的地址)
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //传输方向 外设-内存
DMA_InitStructure.DMA_BufferSize = SPI1_ReciveBufferSize; //设置 SPI1 发送长度
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_Channel2, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel2, DMA_IT_TC, ENABLE);
/* Enable SPI1 DMA RX request */
SPI1->CR2 |= 1<<0; //接收缓冲区DMA使能
DMA_Cmd(DMA1_Channel2, ENABLE);
/* DMA1 Channel3 (triggered by SPI1 Tx event) Config */
DMA_DeInit(DMA1_Channel3);
DMA_InitStructure.DMA_PeripheralBaseAddr = SPI1_DR_Addr; //设置 接收外设(0x4001300C) 地址(源地址)
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)SPI1_TX_Buff; //设置 SRAM 存储地址(源地址)
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //传输方向 内存-外设
DMA_InitStructure.DMA_BufferSize = SPI1_SendBufferSize; //设置 SPI1 接收长度
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_Channel3, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel3, DMA_IT_TC, ENABLE); //开启 DMA1_Channel3 传输完成中断
DMA_ITConfig(DMA1_Channel3, DMA_IT_TE, ENABLE); //开启 DMA1_Channel3 传输错误中断
/* Enable SPI1 DMA TX request */
SPI1->CR2 |= 1<<1; //发送缓冲区DMA使能
DMA_Cmd(DMA1_Channel3, DISABLE); //开启 DMA 通道 DMA1_Channel3
}
|