问答

汇集网友智慧,解决技术难题

21ic问答首页 - GD32F103 AD采样问题

AD采样 AD采样 gd32F103 IO 模拟 电压

GD32F103 AD采样问题

luzimo_pan2021-07-21
GD32F103 IO口设置成模拟输入时,发现IO口有高电平输出,导致ad采样电压偏高,不知道怎么解决?
回答 +关注 0
2465人浏览 1人回答问题 分享 举报
1 个回答
  • 具体代码如下:
    void dma_config(void)
    {
        /* ADC_DMA_channel configuration */
        dma_parameter_struct dma_data_parameter;
       
        /* ADC DMA_channel configuration */
        dma_deinit(DMA0, DMA_CH0);
       
        /* initialize DMA single data mode */
        dma_data_parameter.periph_addr  = (uint32_t)(&ADC_RDATA(ADC0));
        dma_data_parameter.periph_inc   = DMA_PERIPH_INCREASE_DISABLE;
        dma_data_parameter.memory_addr  = (uint32_t)(&adc_value);
        dma_data_parameter.memory_inc   = DMA_MEMORY_INCREASE_ENABLE;
        dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
        dma_data_parameter.memory_width = DMA_MEMORY_WIDTH_16BIT;
        dma_data_parameter.direction    = DMA_PERIPHERAL_TO_MEMORY;
        dma_data_parameter.number       = 5U;
        dma_data_parameter.priority     = DMA_PRIORITY_HIGH;
        dma_init(DMA0, DMA_CH0, &dma_data_parameter);
        dma_circulation_enable(DMA0, DMA_CH0);
      
        /* enable DMA channel */
        dma_channel_enable(DMA0, DMA_CH0);
    }
    void adcinit(void)
    {        
           
            rcu_periph_clock_enable(RCU_GPIOA);
            gpio_init(GPIOA,GPIO_MODE_AIN,GPIO_OSPEED_2MHZ, GPIO_PIN_6|GPIO_PIN_7);
            rcu_periph_clock_enable(RCU_GPIOB);
                    gpio_init(GPIOB,GPIO_MODE_AIN,GPIO_OSPEED_50MHZ, GPIO_PIN_0);
            rcu_periph_clock_enable(RCU_GPIOC);
            gpio_init(GPIOC,GPIO_MODE_AIN,GPIO_OSPEED_50MHZ, GPIO_PIN_5);

               /* enable DMA0 clock */
        rcu_periph_clock_enable(RCU_DMA0);  
                    dma_config();
               rcu_periph_clock_enable(RCU_ADC0);
              /* config ADC clock */
                    rcu_apb2_clock_config(RCU_APB2_CKAHB_DIV4);
        rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV8);
                /* reset ADC */
       adc_deinit(ADC0);
        /* ADC mode config */
        adc_mode_config(ADC_MODE_FREE);
                    adc_tempsensor_vrefint_enable();
        /* ADC contineous function enable */
        adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE, ENABLE);
        /* ADC scan mode disable */
        adc_special_function_config(ADC0, ADC_SCAN_MODE, ENABLE);
        /* ADC data alignment config */
        adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT);
        /* ADC channel length config */
        adc_channel_length_config(ADC0, ADC_REGULAR_CHANNEL, 5);

        /* ADC regular channel config */
        adc_regular_channel_config(ADC0, 0, ADC_CHANNEL_6, ADC_SAMPLETIME_239POINT5);
        adc_regular_channel_config(ADC0, 1, ADC_CHANNEL_7, ADC_SAMPLETIME_239POINT5);
        adc_regular_channel_config(ADC0, 2, ADC_CHANNEL_15, ADC_SAMPLETIME_239POINT5);
        adc_regular_channel_config(ADC0, 3, ADC_CHANNEL_8, ADC_SAMPLETIME_239POINT5);
              adc_regular_channel_config(ADC0, 4, ADC_CHANNEL_17, ADC_SAMPLETIME_239POINT5);
        /* ADC trigger config */
        adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL, ADC0_1_2_EXTTRIG_REGULAR_NONE);
        adc_external_trigger_config(ADC0, ADC_REGULAR_CHANNEL, ENABLE);
       
        /* enable ADC interface */
        adc_enable(ADC0);
        delay_1ms(1);
        /* ADC calibration and reset calibration */
        adc_calibration_enable(ADC0);

        /* ADC DMA function enable */
        adc_dma_mode_enable(ADC0);
        /* ADC software trigger enable */
        adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);


    }

您需要登录后才可以回复 登录 | 注册