我在官方的BLE_UART例程中增加了ADC+DMA采集,但是无法读取到采集的电压值(采集值固定不变),更换其他采集模式问题相同,无法采集数据。
#define BSP_ADC_PORT GPIOA
#define BSP_ADC_PIN GPIO_Pin_1
#define BSP_ADC_GPIO_RCC_PeriphClockCmd RCC_APB2PeriphClockCmd
#define BSP_ADC_GPIO_RCC_Periph RCC_APB2Periph_GPIOA
#define BSP_ADCx ADC1
#define BSP_ADC_CHANNELx ADC_Channel_1
#define BSP_ADC_GPIO_RCC_PeriphClockCmd RCC_APB2PeriphClockCmd
#define BSP_ADC_RCC_Periph RCC_APB2Periph_ADC1
int16_t Calibrattion_Val = 0;
uint16_t ADC_Value_Buf[64] = {0};
void power_ADC_Init(void)
{
? ? BSP_ADC_GPIO_RCC_PeriphClockCmd(BSP_ADC_GPIO_RCC_Periph,ENABLE);
? ? BSP_ADC_GPIO_RCC_PeriphClockCmd (BSP_ADC_RCC_Periph,ENABLE);
? ? RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
? ? RCC_ADCCLKConfig(RCC_PCLK2_Div8);
? ? GPIO_InitTypeDef GPIO_InitStructure = {0};
? ? ADC_InitTypeDef ADC_InitStructure = {0};
? ? DMA_InitTypeDef DMA_InitStructure = {0};
? ? GPIO_InitStructure.GPIO_Pin = BSP_ADC_PIN;
? ? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
? ? GPIO_Init(BSP_ADC_PORT,&GPIO_InitStructure);
? ? ADC_DeInit(BSP_ADCx);
? ? ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
? ? ADC_InitStructure.ADC_ScanConvMode = DISABLE;
? ? ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
? ? ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
? ? ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
? ? ADC_InitStructure.ADC_NbrOfChannel = BSP_ADC_CHANNELx;
? ? ADC_Init(BSP_ADCx, &ADC_InitStructure);
? ? ADC_DMACmd(BSP_ADCx, ENABLE);
? ? ADC_Cmd(BSP_ADCx, ENABLE);
? ? ADC_BufferCmd(BSP_ADCx, DISABLE); //disable buffer
? ? ADC_ResetCalibration(BSP_ADCx);
? ? while(ADC_GetResetCalibrationStatus(BSP_ADCx));
? ? ADC_StartCalibration(BSP_ADCx);
? ? while(ADC_GetCalibrationStatus(BSP_ADCx));
? ? Calibrattion_Val = Get_CalibrationValue(BSP_ADCx);
//? ? Log_printf("CalibrattionValue:%d\n", Calibrattion_Val);
? ? DMA_DeInit(DMA1_Channel1);
? ? DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->RDATAR;
? ? DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_Value_Buf;
? ? DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
? ? DMA_InitStructure.DMA_BufferSize = 1;
? ? DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
? ? DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
? ? DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
? ? DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
? ? DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
? ? DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
? ? DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
? ? DMA_Init(DMA1_Channel1, &DMA_InitStructure);
? ? DMA_Cmd(DMA1_Channel1, ENABLE);
? ? ADC_RegularChannelConfig(BSP_ADCx,BSP_ADC_CHANNELx,1,ADC_SampleTime_55Cycles5);
? ? ADC_SoftwareStartConvCmd(BSP_ADCx,ENABLE);
}