本帖最后由 〽️〽️〽️ 于 2020-7-13 12:30 编辑
uint16_t adc_value;
//ADC脚是 PA3
int main(void)
{
//......时钟配置
//......初始化其他配置
recv_config();
while(1)
{
while (RESET == dma_flag_get(DMA_CH0, DMA_FLAG_FTF)){;}
if(adc_value>100)
{
//ADC值一直是0x0000
}
//.....LED周期闪正常
}
}
void recv_config(void)
{
rcu_config();
gpio_config();
dma_config();
adc_config();
}
void rcu_config(void)
{
/* enable GPIOC clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* enable DMA clock */
rcu_periph_clock_enable(RCU_DMA);
/* enable ADC clock */
rcu_periph_clock_enable(RCU_ADC);
/* config ADC clock */
rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
}
void gpio_config(void)
{
/* config the GPIO as analog mode */
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_3);
}
void dma_config(void)
{
/* ADC_DMA_channel configuration */
dma_deinit(DMA_CH0);
dma_periph_address_config(DMA_CH0,(uint32_t)(&ADC_RDATA));
dma_memory_address_config(DMA_CH0,(uint32_t)(&adc_value));
dma_transfer_direction_config(DMA_CH0,DMA_PERIPHERAL_TO_MEMORY);
dma_memory_width_config(DMA_CH0,DMA_MEMORY_WIDTH_16BIT);
dma_periph_width_config(DMA_CH0,DMA_PERIPHERAL_WIDTH_16BIT);
dma_priority_config(DMA_CH0,DMA_PRIORITY_HIGH);
dma_transfer_number_config(DMA_CH0,1);
dma_periph_increase_disable(DMA_CH0);
dma_memory_increase_enable(DMA_CH0);
dma_circulation_enable(DMA_CH0);
dma_channel_enable(DMA_CH0);
}
void adc_config(void)
{
/* ADC channel length config */
adc_channel_length_config(ADC_REGULAR_CHANNEL,1);
/* ADC regular channel config */
adc_regular_channel_config(0,ADC_CHANNEL_3,ADC_SAMPLETIME_55POINT5);
/* ADC external trigger enable */
adc_external_trigger_config(ADC_REGULAR_CHANNEL,ENABLE);
/* ADC external trigger source config */
adc_external_trigger_source_config(ADC_REGULAR_CHANNEL,ADC_EXTTRIG_REGULAR_SWRCST);
/* ADC data alignment config */
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
/* enable ADC interface */
adc_enable();
/* ADC calibration and reset calibration */
adc_calibration_enable();
/* ADC DMA function enable */
adc_dma_mode_enable();
/* ADC contineous function enable */
adc_special_function_config(ADC_CONTINUOUS_MODE,ENABLE);
/* ADC software trigger enable */
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
} |