二:DMA的初始化static void ADCx_Mode_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
//打开DMA时钟
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
//复位DMA
DMA_DeInit(ADC_DMA_CHANNEL);
DMA_InitStructure.DMA_PeripheralBaseAddr = ( uint32_t ) ( & (ADC_x->DR ) );
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC_ConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
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;//Normal是一直传输
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(ADC_DMA_CHANNEL,&DMA_InitStructure);
DMA_Cmd(ADC_DMA_CHANNEL,ENABLE);
ADC_InitTypeDef ADC_InitStruct;
ADC_APBxClock_FUN ( ADC_CLK, ENABLE );
ADC_InitStruct.ADC_Mode = ADC_Mode_Independent;
ADC_InitStruct.ADC_ScanConvMode = DISABLE;
ADC_InitStruct.ADC_ContinuousConvMode = ENABLE; //一直转换
ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; //软件触发
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right; //右对齐
ADC_InitStruct.ADC_NbrOfChannel = 1; //转换通道为一个
ADC_Init(ADC_x, &ADC_InitStruct);
RCC_ADCCLKConfig(RCC_PCLK2_Div8);
ADC_RegularChannelConfig(ADC_x, ADC_CHANNEL,1, ADC_SampleTime_55Cycles5);
//使能ADC DMA请求
ADC_DMACmd(ADC_x,ENABLE);
ADC_Cmd(ADC_x,ENABLE);
//校准ADC
ADC_StartCalibration(ADC_x);
//等待校准完成
while(ADC_GetCalibrationStatus(ADC_x));
//采用软件触发
ADC_SoftwareStartConvCmd(ADC_x,ENABLE);
}
|