void ADCx_Init(void)
{
dma_parameter_struct dma_data_parameter;
rcu_periph_clock_enable(RCU_GPIOC);
gpio_init(GPIOC, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, GPIO_PIN_0);
gpio_init(GPIOC, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, GPIO_PIN_1);
gpio_init(GPIOC, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, GPIO_PIN_2);
gpio_init(GPIOC, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, GPIO_PIN_3);
rcu_periph_clock_enable(RCU_ADC2);
rcu_periph_clock_enable(RCU_AF);
rcu_periph_clock_enable(RCU_DMA1);
rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV16);
adc_deinit(ADC2);
adc_mode_config(ADC_MODE_FREE);
adc_special_function_config(ADC2, ADC_CONTINUOUS_MODE, ENABLE);
/* ADC scan mode disable */
adc_special_function_config(ADC2, ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC2, ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC2, ADC_REGULAR_CHANNEL, NOFCHANEL);//常规通道长度配置
/* ADC regular channel config */
adc_regular_channel_config(ADC2, 0, ADC_CHANNEL_10, ADC_SAMPLETIME_239POINT5);
adc_regular_channel_config(ADC2, 1, ADC_CHANNEL_11, ADC_SAMPLETIME_239POINT5);
adc_regular_channel_config(ADC2, 2, ADC_CHANNEL_12, ADC_SAMPLETIME_239POINT5);
adc_regular_channel_config(ADC2, 3, ADC_CHANNEL_13, ADC_SAMPLETIME_239POINT5);
/* ADC trigger config */
adc_external_trigger_source_config(ADC2,ADC_REGULAR_CHANNEL, ADC0_1_2_EXTTRIG_REGULAR_NONE);
adc_external_trigger_config(ADC2, ADC_REGULAR_CHANNEL, ENABLE);
/* ADC DMA function enable */
adc_dma_mode_enable(ADC2);//使能 DMA 模式
/* enable ADC interface */
adc_enable(ADC2);
delay_ms(2);
/* ADC calibration and reset calibration */
adc_calibration_enable(ADC2);
/* ADC_DMA_channel configuration */
/* ADC DMA_channel configuration */
dma_deinit(DMA1,DMA_CH4);
/* initialize DMA single data mode */
dma_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA(ADC2)); //外设地址
dma_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_data_parameter.memory_addr = (uint32_t)(&ADC_ConvertedValue); //搬运目标地址
dma_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
dma_data_parameter.memory_width = DMA_MEMORY_WIDTH_16BIT;
dma_data_parameter.direction = DMA_PERIPHERAL_TO_MEMORY;
dma_data_parameter.number = 4;
dma_data_parameter.priority = DMA_PRIORITY_HIGH;
dma_init(DMA1, DMA_CH4, &dma_data_parameter);
/* enable DMA circulation mode */
dma_circulation_enable(DMA1, DMA_CH4);
/* enable DMA channel */
dma_channel_enable(DMA1, DMA_CH4);
adc_software_trigger_enable(ADC2,ADC_REGULAR_CHANNEL);
} |