u16 g_ADC_ConvertedValue[2];
我的初始化代码如下:
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
/* Enable GPIOA clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
/* Enable DMA clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* Enable ADC1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* Configure PA1 (ADC Channel1) as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* DMA Channel1 Configuration ----------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)g_ADC_ConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 2;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
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_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* ADC1 Configuration (ADC1CLK = 18 MHz) -----------------------------------*/
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 2;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 Regular Channel1 Configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 1, ADC_SampleTime_55Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 2, ADC_SampleTime_55Cycles5);
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
// while(ADC_GetCalibrationStatus(ADC1));
ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1's DMA interface */
ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 */
ADC_SoftwareStartConvCmd(ADC1,ENABLE);/* Start ADC1 Software Conversion */
DMA_Cmd(DMA1_Channel1, ENABLE); /* Enable DMA Channel1 */
现在出现的问题是,通过定时器取g_ADC_ConvertedValue[0],g_ADC_ConvertedValue[1]的值,结果总是在g_ADC_ConvertedValue[0]中,而且两路的值在g_ADC_ConvertedValue[0]中随机变化,g_ADC_ConvertedValue[1]确总是为0。请问是什么原因啊?DMA与两路ADC的值如何与我的缓冲区对应起来?以下是实际数据。
battery ad=2048 temp ad=0
battery ad=3275 temp ad=0
battery ad=3228 temp ad=0
battery ad=3164 temp ad=0
battery ad=3273 temp ad=0
battery ad=2049 temp ad=0
battery ad=3278 temp ad=0
battery ad=3273 temp ad=0 |