static void adc1_init(void)
{
adc_base_config_type adc_base_struct;
crm_periph_clock_enable(CRM_ADC1_PERIPH_CLOCK, TRUE);
adc_base_default_para_init(&adc_base_struct);
adc_base_struct.sequence_mode = TRUE;
adc_base_struct.repeat_mode = FALSE;
adc_base_struct.data_align = ADC_RIGHT_ALIGNMENT;
adc_base_struct.ordinary_channel_length = 7;
adc_base_config(ADC1, &adc_base_struct);
adc_resolution_set(ADC1, ADC_RESOLUTION_12B);
for (uint8_t i = 0; i < BSP_ADC1_USED_NUM; i++)
{
bsp_gpio_pin_init(bsp_adc_pin[adc1_used_ch[i]].port,
bsp_adc_pin[adc1_used_ch[i]].pin,
BSP_GPIO_MODE_AN,
BSP_GPIO_DRV_MODERATE,
BSP_GPIO_PUPD_NULL,
BSP_GPIO_OTYPE_OD);
}
/* config ordinary channel */
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_13, 1, ADC_SAMPLETIME_640_5);
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_0, 2, ADC_SAMPLETIME_640_5);
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_8, 3, ADC_SAMPLETIME_640_5);
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_9, 4, ADC_SAMPLETIME_640_5);
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_10, 5, ADC_SAMPLETIME_640_5);
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_12, 6, ADC_SAMPLETIME_640_5);
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_3, 7, ADC_SAMPLETIME_640_5);
/* config ordinary trigger source and trigger edge */
adc_ordinary_conversion_trigger_set(ADC1, ADC_ORDINARY_TRIG_TMR2CH2, ADC_ORDINARY_TRIG_EDGE_RISING);
/* config dma mode,it's not useful when common dma mode is use */
adc_dma_mode_enable(ADC1, TRUE);
/* config dma request repeat,it's not useful when common dma mode is use */
adc_dma_request_repeat_enable(ADC1, TRUE);
/* adc enable */
adc_enable(ADC1, TRUE);
while (adc_flag_get(ADC1, ADC_RDY_FLAG) == RESET)
;
/* adc calibration */
adc_calibration_init(ADC1);
while (adc_calibration_init_status_get(ADC1))
;
adc_calibration_start(ADC1);
while (adc_calibration_status_get(ADC1))
;
} |