这是我写的代码,还请各位大神帮忙看一下。外部引脚上有电压,但是ad的规则数据寄存器中始终没有数据。
#include "bsp_adc.h"
__IO uint16_t adc_value[2];
void gpio_config(void)
{
rcu_periph_clock_enable(RCU_GPIOA);
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_1);
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_6);
}
void dma_config(void)
{
//DMA配置结构体
dma_single_data_parameter_struct dma_single_data_parameter;
//开启DMA1时钟
rcu_periph_clock_enable(RCU_DMA1);
//复位DMA1的通道0
dma_deinit(DMA1, DMA_CH0);
//配置DMA结构体
dma_single_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA(ADC0));
dma_single_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_single_data_parameter.memory0_addr = (uint32_t)(adc_value);
dma_single_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_single_data_parameter.periph_memory_width = DMA_PERIPH_WIDTH_16BIT;
dma_single_data_parameter.direction = DMA_PERIPH_TO_MEMORY;
dma_single_data_parameter.number = 2;
dma_single_data_parameter.priority = DMA_PRIORITY_HIGH;
dma_single_data_mode_init(DMA1, DMA_CH0, &dma_single_data_parameter);
dma_channel_subperipheral_select(DMA1, DMA_CH0, DMA_SUBPERI0);
dma_circulation_enable(DMA1, DMA_CH0); //循环模式
dma_channel_enable(DMA1, DMA_CH0); //使能DMA通道
}
void adc_config(void)
{
rcu_periph_clock_enable(RCU_ADC0); //配置ADC0时钟
adc_clock_config(ADC_ADCCK_PCLK2_DIV6); //时钟6分频
adc_deinit(); //ADC寄存器恢复默认值
/* ADC mode config */
adc_sync_mode_config(ADC_SYNC_MODE_INDEPENDENT);//
/* ADC contineous function disable */
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_resolution_config(ADC0,ADC_RESOLUTION_12B);
/* ADC channel length config */
adc_channel_length_config(ADC0, ADC_REGULAR_CHANNEL, 2);
adc_regular_channel_config(ADC0, 0, ADC_CHANNEL_1, ADC_SAMPLETIME_15);
adc_regular_channel_config(ADC0, 1, ADC_CHANNEL_6, ADC_SAMPLETIME_15);
// /* ADC trigger config */
adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_T0_CH0);
adc_external_trigger_config(ADC0, ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_DISABLE);
/* enable ADC interface */
adc_enable(ADC0);
delay_ms(1);
/* ADC DMA function enable */
adc_dma_request_after_last_enable(ADC0);
adc_dma_mode_enable(ADC0);
/* ADC calibration and reset calibration */
adc_calibration_enable(ADC0);
delay_ms(1);
/* enable ADC software trigger */
adc_software_trigger_enable(ADC0, ADC_REGULAR_CHANNEL);
}
void adc_init(void)
{
gpio_config();
dma_config();
adc_config();
}
|