int main(void)
{
/* system clocks configuration */
rcu_config();
/* systick configuration */
systick_config();
/* GPIO configuration */
gpio_config();
/* DMA configuration */
dma_config();
/* ADC configuration */
adc_config();
/* configure COM port */
gd_eval_com_init(EVAL_COM0);
while(1){
delay_1ms(1000);
printf("\r\n *******************************");
printf("\r\n ADC2 regular channel data = %5.4fV\r\n", adc_value[0]*3.3/4096);
}
}
/*!
\brief configure the different system clocks
\param[in] none
\param[out] none
\retval none
*/
void rcu_config(void)
{
/* enable GPIOC clock */
rcu_periph_clock_enable(RCU_GPIOF);
/* enable ADC clock */
rcu_periph_clock_enable(RCU_ADC2);
/* enable timer1 clock */
rcu_periph_clock_enable(RCU_TIMER1);
rcu_timer_clock_prescaler_config(RCU_TIMER_PSC_MUL4);
/* enable DMA clock */
rcu_periph_clock_enable(RCU_DMA1);
/* config ADC clock */
adc_clock_config(ADC_ADCCK_PCLK2_DIV6);
}
/*!
\brief configure the GPIO peripheral
\param[in] none
\param[out] none
\retval none
*/
void gpio_config(void)
{
/* config the GPIO as analog mode */
//gpio_mode_set(GPIOF, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
gpio_mode_set(GPIOF, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_6);
}
/*!
\brief configure the DMA peripheral
\param[in] none
\param[out] none
\retval none
*/
void dma_config(void)
{
/* ADC_DMA_channel configuration */
dma_single_data_parameter_struct dma_single_data_parameter;
/* ADC DMA_channel configuration */
dma_deinit(DMA1, DMA_CH0);
/* initialize DMA single data mode */
dma_single_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA(ADC2));
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 = 1;
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);
/* enable DMA circulation mode */
dma_circulation_enable(DMA1, DMA_CH0);
/* enable DMA channel */
dma_channel_enable(DMA1, DMA_CH0);
}
/*!
\brief configure the ADC peripheral
\param[in] none
\param[out] none
\retval none
*/
void adc_config(void)
{
/* ADC mode config */
adc_sync_mode_config(ADC_SYNC_MODE_INDEPENDENT);
/* ADC contineous function disable */
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, 1);
/* ADC regular channel config */
adc_regular_channel_config(ADC2, 0, ADC_CHANNEL_4, ADC_SAMPLETIME_15);
//adc_regular_channel_config(ADC0, 1, ADC_CHANNEL_2, ADC_SAMPLETIME_15);
//adc_regular_channel_config(ADC0, 2, ADC_CHANNEL_3, ADC_SAMPLETIME_15);
//adc_regular_channel_config(ADC0, 3, BOARD_ADC_CHANNEL, ADC_SAMPLETIME_15);
/* ADC trigger config */
adc_external_trigger_source_config(ADC2, ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_T0_CH0);
adc_external_trigger_config(ADC2, ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_DISABLE);
/* ADC DMA function enable */
adc_dma_request_after_last_enable(ADC2);
adc_dma_mode_enable(ADC2);
/* enable ADC interface */
adc_enable(ADC2);
/* wait for ADC stability */
delay_1ms(1);
/* ADC calibration and reset calibration */
adc_calibration_enable(ADC2);
/* enable ADC software trigger */
adc_software_trigger_enable(ADC2, ADC_REGULAR_CHANNEL);
}
这个程序是官方demo改的,AD0可以正常获取数据,但是AD2不行,为什么?? |