/* Definition of ADCx conversions data table size */
#define ADC_CONVERTED_DATA_BUFFER_SIZE ((uint32_t) 2)
/* Variables for ADC conversion data */
__IO uint16_t aADCxConvertedData[ADC_CONVERTED_DATA_BUFFER_SIZE]; /* ADC group regular conversion data */
void GD_DMA_Init(void)
{
/* DMA controller clock enable */
rcu_periph_clock_enable(RCU_DMA1);
/* DMA interrupt init */
/* ADC_DMA_channel configuration */
dma_single_data_parameter_struct dma_single_data_parameter;
/* ADC DMA_channel configuration */
dma_deinit(DMA1, DMA_CH0);
/* initialize DMA single data mode */
dma_single_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA(ADC0));
dma_single_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_single_data_parameter.memory0_addr = (uint32_t)(aADCxConvertedData);
dma_single_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_single_data_parameter.periph_memory_width = DMA_PERIPH_WIDTH_16BIT;
dma_single_data_parameter.direction = DMA_PERIPH_TO_MEMORY;
dma_single_data_parameter.number = 2;
dma_single_data_parameter.priority = DMA_PRIORITY_LOW;
dma_single_data_mode_init(DMA1, DMA_CH0, &dma_single_data_parameter);
dma_channel_subperipheral_select(DMA1, DMA_CH0, DMA_SUBPERI0);
/* enable DMA circulation mode */
dma_circulation_enable(DMA1, DMA_CH0);
/* enable DMA channel */
dma_channel_enable(DMA1, DMA_CH0);
}
void GD_ADC_Init(void)
{
GD_ADC_MspInit();
/* config ADC clock */
adc_clock_config(ADC_ADCCK_PCLK2_DIV4);
/* ADC mode config */
adc_sync_mode_config(ADC_SYNC_MODE_INDEPENDENT);
/* ADC contineous function disable */
adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE, ENABLE);
/* ADC scan mode disable */
adc_special_function_config(ADC0, ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC0, ADC_REGULAR_CHANNEL, 2);
/* ADC regular channel config */
adc_regular_channel_config(ADC0, 0, ADC_CHANNEL_0, ADC_SAMPLETIME_144);
adc_regular_channel_config(ADC0, 1, ADC_CHANNEL_10, ADC_SAMPLETIME_144);
/* ADC trigger config */
adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_T0_CH0);
adc_external_trigger_config(ADC0, ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_DISABLE);
adc_end_of_conversion_config(ADC0, ADC_EOC_SET_CONVERSION);
/* ADC DMA function enable */
adc_dma_request_after_last_enable(ADC0);
adc_dma_mode_enable(ADC0);
/* enable ADC interface */
adc_enable(ADC0);
/* wait for ADC stability */
delay_ms(1);
/* ADC calibration and reset calibration */
adc_calibration_enable(ADC0);
/* enable ADC software trigger */
adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);
}
void GD_ADC_MspInit(void)
{
/* enable ADC clock */
rcu_periph_clock_enable(RCU_ADC0);
/* config the GPIO as analog mode */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0);
gpio_mode_set(GPIOC, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0);
}
void GD_ADC_MspDeInit(void)
{
rcu_periph_clock_disable(RCU_ADC0);
gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_0);
gpio_mode_set(GPIOC, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_0);
}
|