DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
以下是stm32f10x_dma.c中有关DMA的初始化设置代码
tmpreg |= DMA_InitStruct-》DMA_DIR | DMA_InitStruct-》DMA_Mode |
DMA_InitStruct-》DMA_PeripheralInc | DMA_InitStruct-》DMA_MemoryInc |
DMA_InitStruct-》DMA_PeripheralDataSize | DMA_InitStruct-》DMA_MemoryDataSize |
DMA_InitStruct-》DMA_Priority | DMA_InitStruct-》DMA_M2M;
/* Write to DMAy Channelx CCR */
DMAy_Channelx-》CCR = tmpreg;
/*--------------------------- DMAy Channelx CNDTR Configuration ---------------*/
/* Write to DMAy Channelx CNDTR */
DMAy_Channelx-》CNDTR = DMA_InitStruct-》DMA_BufferSize;
/*--------------------------- DMAy Channelx CPAR Configuration ----------------*/
/* Write to DMAy Channelx CPAR */
DMAy_Channelx-》CPAR = DMA_InitStruct-》DMA_PeripheralBaseAddr;
/*--------------------------- DMAy Channelx CMAR Configuration ----------------*/
/* Write to DMAy Channelx CMAR */
DMAy_Channelx-》CMAR = DMA_InitStruct-》DMA_MemoryBaseAddr;
//内存地址送入CMAR寄存器
说明:这个图从PDF截下来,图中那个DMA_CPARx写错了,应该是DMA_CMARx
------------------------------------------------------------------------------------------
再来看一个DMA的例子
/* DMA1 Channel5 configuration ----------------------------------------------*/
DMA_DeInit(DMA1_Channel5);
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)TIM1_CCR1_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC1_DR_Address;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
/* Enable DMA1 Channel5 */
DMA_Cmd(DMA1_Channel5, ENABLE);
还有一些目前暂时还没有去搞清楚的,比如中断处理等,等到需要时再看吧。
——下次将讨论学习用认识ADC兼进一步看懂STM的库,敬请继续关注。
评论
查看更多