// adc_base_config_type adc_common_struct;
adc_base_config_type adc_base_struct;
gpio_init_type gpio_initstructure;
dma_init_type dma_init_struct;
crm_periph_clock_enable(CRM_GPIOA_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
gpio_default_para_init(&gpio_initstructure);
// ADC_V ADC_NTC
gpio_initstructure.gpio_pins = GPIO_PINS_2 | GPIO_PINS_4 ;
gpio_initstructure.gpio_mode = GPIO_MODE_ANALOG;
gpio_init(GPIOA, &gpio_initstructure);
gpio_default_para_init(&gpio_initstructure);
// ADC_VBC ADC_A
gpio_initstructure.gpio_pins = GPIO_PINS_0 | GPIO_PINS_1 ;
gpio_initstructure.gpio_mode = GPIO_MODE_ANALOG;
gpio_init(GPIOB, &gpio_initstructure);
crm_periph_clock_enable(CRM_DMA1_PERIPH_CLOCK, TRUE);
nvic_irq_enable(DMA1_Channel1_IRQn, 1, 3);
dma_reset(DMA1_CHANNEL1);
dma_flexible_config(DMA1, FLEX_CHANNEL1, DMA_FLEXIBLE_ADC1);
dma_default_para_init(&dma_init_struct);
dma_init_struct.buffer_size = Collection_num * ADC_CH_NUM;
dma_init_struct.direction = DMA_DIR_PERIPHERAL_TO_MEMORY;
dma_init_struct.memory_base_addr = (uint32_t)adc1_ordinary_valuetab;
dma_init_struct.memory_data_width = DMA_MEMORY_DATA_WIDTH_HALFWORD;
dma_init_struct.memory_inc_enable = TRUE;
dma_init_struct.peripheral_base_addr = (uint32_t) & (ADC1->odt);
dma_init_struct.peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_HALFWORD;
dma_init_struct.peripheral_inc_enable = FALSE;
dma_init_struct.priority = DMA_PRIORITY_HIGH;
dma_init_struct.loop_mode_enable = TRUE;
dma_init(DMA1_CHANNEL1, &dma_init_struct);
dma_interrupt_enable(DMA1_CHANNEL1, DMA_FDT_INT, TRUE);
dma_channel_enable(DMA1_CHANNEL1, TRUE);
crm_periph_clock_enable(CRM_ADC1_PERIPH_CLOCK, TRUE);
crm_adc_clock_div_set(CRM_ADC_DIV_6);
//nvic_irq_enable(ADC1_IRQn, 0, 0);
adc_base_default_para_init(&adc_base_struct);
adc_base_struct.sequence_mode = TRUE; // adc序列模式
adc_base_struct.repeat_mode = TRUE; //反复模式
adc_base_struct.data_align = ADC_RIGHT_ALIGNMENT;
adc_base_struct.ordinary_channel_length = ADC_CH_NUM;
adc_base_config(ADC1, &adc_base_struct);
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_17,1, ADC_SAMPLETIME_7_5);
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_9 , 2, ADC_SAMPLETIME_7_5);
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_8 , 3, ADC_SAMPLETIME_7_5);
adc_ordinary_channel_set(ADC1, ADC_CHANNEL_2, 4, ADC_SAMPLETIME_7_5);
adc_ordinary_channel_set(ADC1,ADC_CHANNEL_4 , 5, ADC_SAMPLETIME_7_5);
/* 配置普通触发源和触发沿 */
adc_ordinary_conversion_trigger_set(ADC1, ADC12_ORDINARY_TRIG_SOFTWARE, TRUE);
/* 配置dma模式,使用普通dma模式时无用 */
adc_dma_mode_enable(ADC1, TRUE);
// /* 启用ADC溢出中断 */
// adc_interrupt_enable(ADC1, ADC_CCE_INT, FALSE);
/* 设置超采样率和移位 */
adc_oversample_ratio_shift_set(ADC1, ADC_OVERSAMPLE_RATIO_4, ADC_OVERSAMPLE_SHIFT_0);
/* 禁用普通超采样触发模式 */
adc_ordinary_oversample_trig_enable(ADC1, FALSE);
/* 设置普通超采样重启模式 */
adc_ordinary_oversample_restart_set(ADC1, ADC_OVERSAMPLE_CONTINUE);
/* 启用普通超采样 */
adc_ordinary_oversample_enable(ADC1, TRUE);
/* 启用抢先超采样 */
adc_preempt_oversample_enable(ADC1, TRUE);
/* 启用内部参考电压 */
adc_tempersensor_vintrv_enable(TRUE);
//电压监测
adc_voltage_monitor_enable(ADC1, ADC_VMONITOR_SINGLE_ORDINARY);
adc_voltage_monitor_threshold_value_set(ADC1, 13500, 11100);
adc_voltage_monitor_single_channel_select(ADC1, ADC_CHANNEL_4);
adc_interrupt_enable(ADC1, ADC_VMOR_INT, TRUE);
adc_enable(ADC1, TRUE);
adc_calibration_init(ADC1); //初始化指定adc外围设备的校准寄存器。
while (adc_calibration_init_status_get(ADC1))
;
adc_calibration_start(ADC1);
while (adc_calibration_status_get(ADC1))
;
adc_ordinary_software_trigger_enable(ADC1, TRUE);