////////////////////////////////////////////////////////////////
///////DMA//////////////////////////////////////////////
/* Enable DMA1 clock */
CLK_PeripheralClockConfig(CLK_Peripheral_DMA1, ENABLE);
/* Connect ADC to DMA channel 0 */
SYSCFG_REMAPDMAChannelConfig(REMAP_DMA1Channel_ADC1ToChannel0);
DMA_Init(DMA1_Channel0, BUFFER_ADDRESS,
ADC1_DR_ADDRESS,
BUFFER_SIZE,
DMA_DIR_PeripheralToMemory,
DMA_Mode_Circular,
DMA_MemoryIncMode_Inc,
DMA_Priority_High,
DMA_MemoryDataSize_HalfWord);
/* DMA Channel0 enable */
DMA_Cmd(DMA1_Channel0, ENABLE);
/* Enable DMA1 channel0 Transfer complete interrupt */
DMA_ITConfig(DMA1_Channel0, DMA_ITx_TC, ENABLE);
/* DMA enable */
DMA_GlobalCmd(ENABLE);
////////////////////////////////////////////////////////////////
///////ADC//////////////////////////////////////////////
/* Enable ADC1 clock */
CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);
/* Initialize and configure ADC1 */
//工作在In continuous conversion mode, the ADC starts another conversion as soon as it finishes one
ADC_Init(ADC1, ADC_ConversionMode_Continuous, ADC_Resolution_12Bit, ADC_Prescaler_2);
ADC_SamplingTimeConfig(ADC1, ADC_Group_SlowChannels, ADC_SamplingTime_384Cycles);
ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels, ADC_SamplingTime_384Cycles);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable ADC1 Channels 4 */
ADC_ChannelCmd(ADC1, ADC_Channel_4, ENABLE); /* connected to Potentiometer RV */
ADC_ChannelCmd(ADC1, ADC_Channel_Vrefint, ENABLE);//测基准电压
/* Enable ADC1 DMA requests*/
ADC_DMACmd(ADC1, ENABLE);
/* Start ADC1 Conversion using TIM1 TRGO*/
ADC_SoftwareStartConv(ADC1); |