ADC配置如下,通过PA5(AD_IN5)采集电池电压,每100ms使用adc_software_trigger_enable(ADC_REGULAR_CHANNEL)触发采集一次数据,每10个数据取中值作为电池的电压有效数据。
void adc_config(void)
{
/* ADC CONTINUOUS function enable */
adc_special_function_config(ADC_CONTINUOUS_MODE,DISABLE);
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL,1);
/* ADC regular channel config */
adc_regular_channel_config(1,ADC_CHANNEL_5,ADC_SAMPLETIME_55POINT5);
/* ADC external trigger enable */
adc_external_trigger_config(ADC_REGULAR_CHANNEL,ENABLE);
/* ADC external trigger source config */
adc_external_trigger_source_config(ADC_REGULAR_CHANNEL,ADC_EXTTRIG_REGULAR_NONE);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* enable ADC interface */
adc_enable();
/* ADC calibration and reset calibration */
adc_calibration_enable();
}
第一条语句ADC_CONTINUOUS_MODE配置成disable时,采集到的是一个固定的值,配置成enable时采集的是0,用过的帮忙看下哪里配置错误了吗?感谢!串口读到的数据如下:
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 0
the Rdata is 1483
the Rdata is 2417
the Rdata is 2945
the Rdata is 3219
the Rdata is 3366
the Rdata is 3437
the Rdata is 3471
the Rdata is 3491
the Rdata is 3496
the Rdata is 3498
the Rdata is 3504
the Rdata is 3503
the Rdata is 3509
the Rdata is 3511
the Rdata is 3516
the Rdata is 3522
the Rdata is 3512
the Rdata is 3510
the Rdata is 3511
the Rdata is 3507
the Rdata is 3504
the Rdata is 3503 |