工程师STM32单片机学习基础手记(4):用PWM实现荧火虫灯(六)
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);
还有一些目前暂时还没有去搞清楚的,比如中断处理等,等到需要时再看吧。
- STM32的曼彻斯特编译码系统设计(02-04)
- STM32学习:ADC/DMA/USART(07-25)
- 采用ARM Cortex-M3单片机和DSP的逆变电源设计(06-24)
- STM32 ADC的采样周期确定(02-22)
- 基于STM32F103RB和CC1101的无线数传模块设计(07-23)
- 详解GPIO在STM32中的几种工作模式(09-24)