这两天在看ADC的实验,试着用直接输出何用DMA输出两种方式来试验,结果直接输出结果正常可以从0到3.2几V,但是用DMA传输就直接从0到0.1几V。
贴上代码,,麻烦各位帮忙看看。
#define ADC1_DR_Address ((uint32_t)0x40012400 + 0x4C)
uint16_t ADC_ConvertedValue;
static void GPIO_ADC_Configuration(void)
{
GPIO_InitTypeDef GPIO_Init_Structure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO,ENABLE);
GPIO_Init_Structure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init_Structure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOC,&GPIO_Init_Structure);
}
void ADC_DMA_Configuration(void)
{
ADC_InitTypeDef ADC_Init_Structure;
DMA_InitTypeDef DMA_Init_Structure;
GPIO_ADC_Configuration();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
DMA_DeInit(DMA1_Channel1);
DMA_Init_Structure.DMA_BufferSize = 1; //´«ÊäµÄ´óС
DMA_Init_Structure.DMA_DIR = DMA_DIR_PeripheralSRC; //ÍâÉè×÷ΪÊý¾Ý´«ÊäµÄÀ´Ô´
DMA_Init_Structure.DMA_M2M = DMA_M2M_Disable;
DMA_Init_Structure.DMA_MemoryBaseAddr = (uint32_t)&ADC_ConvertedValue; //ÄÚ´æµØÖ·(Òª´«ÊäµÄ±äÁ¿µÄÖ¸Õë)
DMA_Init_Structure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //ÄÚ´æÊý¾Ýµ¥Î»
DMA_Init_Structure.DMA_MemoryInc = DMA_MemoryInc_Disable; //Ö¸¶¨ÄÚ´æµØÖ·±£³Ö²»±ä
DMA_Init_Structure.DMA_Mode = DMA_Mode_Circular; //²»¶ÏÑ »·
DMA_Init_Structure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //ADCµÄÊý¾ÝµØÖ·
DMA_Init_Structure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //ÍâÉèÊý¾Ýµ¥Î»
DMA_Init_Structure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //Ö¸¶¨ÍâÉèµØÖ·±£³Ö²»±ä
DMA_Init_Structure.DMA_Priority = DMA_Priority_Medium;
DMA_Init(DMA1_Channel1,&DMA_Init_Structure);
DMA_Cmd(DMA1_Channel1,ENABLE);
ADC_DeInit(ADC1);
ADC_Init_Structure.ADC_ContinuousConvMode = ENABLE;
ADC_Init_Structure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_Init_Structure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_Init_Structure.ADC_Mode = ADC_Mode_Independent;
ADC_Init_Structure.ADC_NbrOfChannel = 1;
ADC_Init_Structure.ADC_ScanConvMode = DISABLE;
ADC_Init(ADC1,&ADC_Init_Structure);
RCC_ADCCLKConfig(RCC_PCLK2_DiARM); //ÅäÖÃADCʱÖÓ£¬×î´ó14M
ADC_RegularChannelConfig(ADC1,ADC_Channel_10,1,ADC_SampleTime_41Cycles5); //¹æÔò×é
ADC_DMACmd(ADC1,ENABLE);
ADC_Cmd(ADC1,ENABLE);
ADC_ResetCalibration(ADC1); //¸´Î»Ð£×¼
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1); //¿ªÊ¼Ð£×¼
while(ADC_GetCalibrationStatus(ADC1));
ADC_SoftwareStartConvCmd(ADC1,ENABLE);
} |