AT32F415使用DMA ADC某几个通道什么也不接,其他通道ADC不正常
//初始化ADCvoid Adc_Init(void)
{
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_0 | 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_tempersensor_vintrv_enable(TRUE);
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_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);
}
其中ADC_V是0V 如果ADC_NTC电压降至0.6VADC_VB的电压就会严重下降,只要ADC_NTC电压升高一点到1V,ADC_VB的电压就正常
本帖最后由 goodjob 于 2024-10-1 12:52 编辑
雅特力的几款MCU,与ADC有关的引脚接外部时如果有可能出现接地的情况,需要加2K左右的限流电阻,即使这个脚不使用ADC功能也得这么做,不然ADC就会出问题。我也不知道为啥 您好,您的程序设置了5个ADC1通道,如何分别获取他们,有代码吗?谢谢 通道间好像是有串扰的
页:
[1]