本次的实验是通过配置DMA来获取ADC采集到的数据的。
软件实现如下:
adc.c文件
#include "adc.h" #define ADC1_DR_Address ((u32)0x40012400+0x4c) //定义ADC1地址 volatile uint16_t ADCConvertedValue[2]; //定义内存地址数组 float AD_Value[2]; static void ADC1_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable ADC1 and GPIOC clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB, ENABLE); /* Configure PC.01 as analog input */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 |GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOB, &GPIO_InitStructure); // PB0,PB1 ,输入时不用设置速率 } static void ADC1_DMA_Config(void) { DMA_InitTypeDef DMA_InitStructure; /* DMA channel1 configuration */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);