哪位高人帮忙看一下。
单通道AD转换,数据通过DMA存放在 ADC_DualConvertedValueTab指向的SRAM中。
现在的现象是AD可以正确采集数据,也可以从AD的数据寄存器中读到正确数据。
问题是:DMA中的数据只有低8位(数据与AD数据寄存器中的一致),高8位的数据为0。
哪位高人帮忙看一下程序,哪里有问题。
程序如下:
#define ADC1_DR_Address ((u32)0x4001244C)
vu16 ADC_DualConvertedValueTab[10];
ADC_InitTypeDef ADC_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
void adc_init(void)
{
// DMA configuration
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //使能DMA时钟
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)ADC1_DR_Address;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_DualConvertedValueTab;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 10;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode =DMA_Mode_Circular; // DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
/* ADC1 configuration ------------------------------------------------------*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE); //使能ADC
RCC_ADCCLKConfig(RCC_PCLK2_Div8) ; //ADC时钟分频 72/8 = 9M
ADC_DeInit(ADC1);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; // single channel use this mode
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 = 1;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channels configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_239Cycles5); //(239.5+12.5)/9=28us
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
ADC_Cmd(ADC1, ENABLE); //开启ADC1
ADC_ResetCalibration(ADC1); //重新校准
while(ADC_GetResetCalibrationStatus(ADC1)); //等待重新校准完成
ADC_StartCalibration(ADC1); //开始校准
while(ADC_GetCalibrationStatus(ADC1)); //等待校准完成
/* Enable DMA Channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
|