static void adc_config(void)
{
adc_base_config_type adc_base_struct;
crm_periph_clock_enable(CRM_ADC1_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_ADC2_PERIPH_CLOCK, TRUE);
crm_adc_clock_div_set(CRM_ADC_DIV_6);
nvic_irq_enable(ADC1_2_IRQn, 0, 0);
/* select combine mode */
adc_combine_mode_select(ADC_PREEMPT_SMLT_ONLY_MODE);
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 = 1;
adc_base_config(ADC1, &adc_base_struct);
adc_preempt_channel_length_set(ADC1, 1);
adc_preempt_channel_set(ADC1, ADC_CHANNEL_7, 1, ADC_SAMPLETIME_239_5);
adc_preempt_conversion_trigger_set(ADC1, ADC12_PREEMPT_TRIG_TMR1TRGOUT, TRUE);
adc_interrupt_enable(ADC1, ADC_PCCE_INT, TRUE);
adc_base_config(ADC2, &adc_base_struct);
adc_preempt_channel_length_set(ADC2, 1);
adc_preempt_channel_set(ADC2, ADC_CHANNEL_3, 1, ADC_SAMPLETIME_239_5);
adc_preempt_conversion_trigger_set(ADC2, ADC12_PREEMPT_TRIG_SOFTWARE, TRUE);
adc_interrupt_enable(ADC2, ADC_PCCE_INT, TRUE);
adc_enable(ADC1, TRUE);
adc_enable(ADC2, TRUE);
adc_calibration_init(ADC1);
while(adc_calibration_init_status_get(ADC1));
adc_calibration_start(ADC1);
while(adc_calibration_status_get(ADC1));
adc_calibration_init(ADC2);
while(adc_calibration_init_status_get(ADC2));
adc_calibration_start(ADC2);
while(adc_calibration_status_get(ADC2));
}
void ADC1_2_IRQHandler(void)
{
if(adc_flag_get(ADC1, ADC_PCCE_FLAG) != RESET)
{
adc_flag_clear(ADC1, ADC_PCCE_FLAG);
adc1_preempt_valuetab = adc_preempt_conversion_data_get(ADC1, ADC_PREEMPT_CHANNEL_1);
}
if(adc_flag_get(ADC2, ADC_PCCE_FLAG) != RESET)
{
adc_flag_clear(ADC2, ADC_PCCE_FLAG);
adc1_preempt_valuetab = adc_preempt_conversion_data_get(ADC2, ADC_PREEMPT_CHANNEL_1);
}
}
|