21ic问答首页 - GD32F103ZET6内部ADC2有没有
GD32F103ZET6内部ADC2有没有
l4598296342024-06-25
使用官方的库函数,ADC2根本无法初始化dma_parameter_struct dma_data_parameter;
rcu_periph_clock_enable(RCU_GPIOF);
rcu_periph_clock_enable(RCU_ADC2);
rcu_periph_clock_enable(RCU_DMA1);
/*配置PF*/
gpio_init(GPIOF, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
/* ADC DMA_channel configuration */
dma_deinit(DMA1, DMA_CH4);
/* initialize DMA single data mode */
dma_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA(ADC2));
dma_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_data_parameter.memory_addr = (uint32_t)(&ADC2_ConvertedValue);
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 = M1*N1;
dma_data_parameter.priority = DMA_PRIORITY_HIGH;
dma_init(DMA1, DMA_CH4, &dma_data_parameter);
dma_circulation_enable(DMA1, DMA_CH4);
/* enable DMA channel */
dma_channel_enable(DMA1, DMA_CH4);
/*ADC配置*/
adc_deinit(ADC2);
/* ADC mode config */
adc_mode_config(ADC_MODE_FREE);
/* ADC contineous function enable */
adc_special_function_config(ADC2, ADC_CONTINUOUS_MODE, ENABLE);
/* ADC scan mode disable */
adc_special_function_config(ADC2, ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC2, ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC2, ADC_REGULAR_CHANNEL, M1);
/*ADC0规则通道配置*/
adc_regular_channel_config(ADC2, 0, ADC_CHANNEL_7, ADC_SAMPLETIME_239POINT5);
adc_regular_channel_config(ADC2, 1, ADC_CHANNEL_8, ADC_SAMPLETIME_239POINT5);
adc_regular_channel_config(ADC2, 2, ADC_CHANNEL_6, ADC_SAMPLETIME_239POINT5);
adc_regular_channel_config(ADC2, 3, ADC_CHANNEL_5, ADC_SAMPLETIME_239POINT5);
/* ADC trigger config */
adc_external_trigger_source_config(ADC2, ADC_REGULAR_CHANNEL, ADC0_1_2_EXTTRIG_REGULAR_NONE);
adc_external_trigger_config(ADC2, ADC_REGULAR_CHANNEL, ENABLE);
/* enable ADC interface */
adc_enable(ADC2);
delay_ms(1);
/* ADC calibration and reset calibration */
adc_calibration_enable(ADC2);
/* ADC DMA function enable */
adc_dma_mode_enable(ADC2);
/* ADC software trigger enable */
adc_software_trigger_enable(ADC2, ADC_REGULAR_CHANNEL);
rcu_periph_clock_enable(RCU_GPIOF);
rcu_periph_clock_enable(RCU_ADC2);
rcu_periph_clock_enable(RCU_DMA1);
/*配置PF*/
gpio_init(GPIOF, GPIO_MODE_AIN, GPIO_OSPEED_50MHZ, GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
/* ADC DMA_channel configuration */
dma_deinit(DMA1, DMA_CH4);
/* initialize DMA single data mode */
dma_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA(ADC2));
dma_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_data_parameter.memory_addr = (uint32_t)(&ADC2_ConvertedValue);
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 = M1*N1;
dma_data_parameter.priority = DMA_PRIORITY_HIGH;
dma_init(DMA1, DMA_CH4, &dma_data_parameter);
dma_circulation_enable(DMA1, DMA_CH4);
/* enable DMA channel */
dma_channel_enable(DMA1, DMA_CH4);
/*ADC配置*/
adc_deinit(ADC2);
/* ADC mode config */
adc_mode_config(ADC_MODE_FREE);
/* ADC contineous function enable */
adc_special_function_config(ADC2, ADC_CONTINUOUS_MODE, ENABLE);
/* ADC scan mode disable */
adc_special_function_config(ADC2, ADC_SCAN_MODE, ENABLE);
/* ADC data alignment config */
adc_data_alignment_config(ADC2, ADC_DATAALIGN_RIGHT);
/* ADC channel length config */
adc_channel_length_config(ADC2, ADC_REGULAR_CHANNEL, M1);
/*ADC0规则通道配置*/
adc_regular_channel_config(ADC2, 0, ADC_CHANNEL_7, ADC_SAMPLETIME_239POINT5);
adc_regular_channel_config(ADC2, 1, ADC_CHANNEL_8, ADC_SAMPLETIME_239POINT5);
adc_regular_channel_config(ADC2, 2, ADC_CHANNEL_6, ADC_SAMPLETIME_239POINT5);
adc_regular_channel_config(ADC2, 3, ADC_CHANNEL_5, ADC_SAMPLETIME_239POINT5);
/* ADC trigger config */
adc_external_trigger_source_config(ADC2, ADC_REGULAR_CHANNEL, ADC0_1_2_EXTTRIG_REGULAR_NONE);
adc_external_trigger_config(ADC2, ADC_REGULAR_CHANNEL, ENABLE);
/* enable ADC interface */
adc_enable(ADC2);
delay_ms(1);
/* ADC calibration and reset calibration */
adc_calibration_enable(ADC2);
/* ADC DMA function enable */
adc_dma_mode_enable(ADC2);
/* ADC software trigger enable */
adc_software_trigger_enable(ADC2, ADC_REGULAR_CHANNEL);
赞0
评论
2024-12-19
赞0
评论
2024-12-19
赞0
评论
2024-12-19
赞0
评论
2024-12-19
赞0
评论
2024-12-19
赞0
评论
2024-12-19
赞0
评论
2024-12-19
赞0
评论
2024-12-19
赞0
评论
2024-12-19
您需要登录后才可以回复 登录 | 注册