小弟拿例程来改,稀里糊涂改出来了。鉴于网上M2M的例子不多,俺就分享一个,抛砖引玉,高人莫笑,有修改意见就更妙了。
ss1[0]='1';
ss1[1]='2';
ss1[2]='3';
ss1[3]='4';
ss1[4]=0x00;
ss2[0]='a';
ss2[1]='b';
ss2[2]='c';
ss2[3]='d';
ss2[4]=0x00;
MYDMA_Config(DMA2_Stream1,DMA_Channel_0,(u32)&ss2,(u32)ss1+1,1);/////ss2 到 ss1
MYDMA_Enable(DMA2_Stream1,2);
//delay_ms(100);
while(1)
{
if(DMA_GetFlagStatus(DMA2_Stream1,DMA_FLAG_TCIF1)!=RESET)//
{
DMA_ClearFlag(DMA2_Stream1,DMA_FLAG_TCIF1);//
break;
}
}
LCD_ShowString(60,600,200,16,16,ss1);
LCD_ShowString(60,700,200,16,16,ss2);
void MYDMA_Config(DMA_Stream_TypeDef *DMA_Streamx,u32 chx,u32 par,u32 mar,u16 ndtr)
{
DMA_InitTypeDef DMA_InitStructure;
if((u32)DMA_Streamx>(u32)DMA2)//
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);//
}else
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);//
}
DMA_DeInit(DMA_Streamx);
while (DMA_GetCmdStatus(DMA_Streamx) != DISABLE){}//
DMA_InitStructure.DMA_Channel = chx;
DMA_InitStructure.DMA_PeripheralBaseAddr = par;//
DMA_InitStructure.DMA_Memory0BaseAddr = mar;//
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToMemory;//
DMA_InitStructure.DMA_BufferSize = ndtr;//
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Enable;//
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_Medium;//
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//
DMA_Init(DMA_Streamx, &DMA_InitStructure);//
}
注释见例程。 |