我這里配置DMA 用USART傳輸數(shù)據(jù)
void DMA_Configuration() { DMA_InitTypeDef DMA_InitStructure;//定義設(shè)置DMA的結(jié)構(gòu)體 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);//使能DMA1的時(shí)鐘 DMA_InitStructure.DMA_PeripheralBaseAddr= (unsigned int)&USART1->DR;//取USART->DR的地址為傳輸目的地 DMA_InitStructure.DMA_MemoryBaseAddr= (u32)a;//取a數(shù)組的地址為起始地 DMA_InitStructure.DMA_DIR= DMA_DIR_PeripheralDST;//設(shè)置外設(shè)作為數(shù)據(jù)傳輸?shù)哪康牡?/div> DMA_InitStructure.DMA_BufferSize= 40;//設(shè)置DMA緩存 DMA_InitStructure.DMA_PeripheralInc= DMA_PeripheralInc_Disable;//設(shè)置外設(shè)地址不增 DMA_InitStructure.DMA_MemoryInc= DMA_MemoryInc_Enable;//設(shè)置內(nèi)存地址自增 DMA_InitStructure.DMA_PeripheralDataSize= DMA_PeripheralDataSize_Byte;//設(shè)置外設(shè)的傳輸數(shù)據(jù)寬度 這里為1個(gè)字節(jié) DMA_InitStructure.DMA_MemoryDataSize= DMA_MemoryDataSize_Byte; //設(shè)置內(nèi)存的數(shù)據(jù)寬度為 1個(gè)字節(jié) DMA_InitStructure.DMA_Mode= DMA_Mode_Circular; //設(shè)置DMA為循環(huán)傳輸模式 DMA_InitStructure.DMA_Priority= DMA_Priority_Medium;// DMA_InitStructure.DMA_M2M= DMA_M2M_Disable;//設(shè)置DMA通道的優(yōu)先級(jí) DMA_Init(DMA1_Channel4,&DMA_InitStructure);//設(shè)置使用DMA1的第四通道為數(shù)據(jù)傳輸通道 DMA_Cmd (DMA1_Channel4,ENABLE); //使能DMA } USART1也要設(shè)置過; 調(diào)用 USART_DMACmd(USART1,USART_DMAReq_Tx, ENABLE); 函數(shù)即可從發(fā)送數(shù)據(jù)這是CPU是空閑的
|