本帖最后由 xiong2088 于 2023-8-8 08:11 编辑
各位大神:
我刚刚接触GD的MCU,在调试GD32F130C8 ADC + DMA的时候发现,DMA搬运数据内存地址没有增长,还有一个就是数据不对, 一直在0xff0~0xffc之间跳动。多方搜素都找不到答案,请各位大神解惑。
ADC只使用一路,PA0。
这是代码:
void ADC_Configuration(void)
{
/* enable ADC clock */
rcu_periph_clock_enable(RCU_ADC);
/* config ADC clock */
rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
/* ADC continuous function enable */
adc_special_function_config(ADC_CONTINUOUS_MODE, ENABLE);
/* ADC scan function enable */
adc_special_function_config(ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL, 1);
/* ADC regular channel config */
adc_regular_channel_config(0, ADC_CHANNEL_1, ADC_SAMPLETIME_55POINT5);
/* ADC trigger config */
adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_NONE);
adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
/* ADC DMA function enable */
adc_dma_mode_enable();
/* enable ADC interface */
adc_enable();
delay_ms(2);
/* ADC calibration and reset calibration */
adc_calibration_enable();
/* ADC software trigger enable */
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
}
void dma_config(void)
{
/* ADC_DMA_channel configuration */
dma_parameter_struct dma_data_parameter;
/* enable DMA clock */
rcu_periph_clock_enable(RCU_DMA);
/* ADC DMA_channel configuration */
dma_deinit(DMA_CH0);
/* initialize DMA single data mode */
dma_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA);
dma_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_data_parameter.memory_addr = (uint32_t)AD_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 = 1;
dma_data_parameter.priority = DMA_PRIORITY_HIGH;
dma_init(DMA_CH0, &dma_data_parameter);
dma_circulation_enable(DMA_CH0);
/* enable DMA channel */
dma_channel_enable(DMA_CH0);
}
请大神指点! |