void Dma_Init(INT32U iDev,INT8U bInt)
{
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //启动DMA时钟
/* DMA1 Channel2 configuration ----------------------------------------------*/
if(iDev==(INT32U)&USART1->TDR)
{
DMA_DeInit(DMA1_Channel2);
DMA_InitStructure.DMA_PeripheralBaseAddr = iDev; //外设地址
DMA_InitStructure.DMA_MemoryBaseAddr = 0; //(u32)TxBuf; //内存地址
DMA_InitStructure.DMA_DIR =DMA_DIR_PeripheralDST; // DMA_DIR_PeripheralSRC; //
DMA_InitStructure.DMA_BufferSize = 0;
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_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel2, &DMA_InitStructure);
USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);
if(bInt==1)
{
NVIC_InitStructure.NVIC_IRQChannel =DMA1_Channel2_3_IRQn; //DMAChannel7_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DMA_ITConfig(DMA1_Channel2,DMA_IT_TC,ENABLE);
}
}
}
void DmaSendData(DMA_Channel_TypeDef* pDmaChnl,INT8U* pSrc,INT32U len)
{
DMA_Cmd(pDmaChnl,DISABLE); //停止使能 才能修改计数器
pDmaChnl->CNDTR=len;
pDmaChnl->CMAR=(INT32U)pSrc;
DMA_Cmd(pDmaChnl,ENABLE); //启动发送
}
|