STM32L151多通道ADC采样,DMA输出,通过串口打印出来,数据不正常。求高手帮忙。
代码如下:
uint32_t ADC_Converted_Value_Table[6] = {0,0,0,0,0,0};
void ADC_DMA_Init(void)
{
DMA_InitTypeDef DMA_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
/*Enable DMA1 Clock*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
/*DMA1 Channel1 Configuration*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_ADDRESS;
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_Converted_Value_Table;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 6;
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_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1,&DMA_InitStructure);
/*ENABLE DMA1 CHANNEL1*/
DMA_Cmd(DMA1_Channel1,ENABLE);
/*------------ADC1 configuration with DMA enabled---------*/
/*Enable the HSI oscillator*/
RCC_HSICmd(ENABLE);
/*Enable GPIOA Clock*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);
/*Enable GPIOB Clock*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);
/*Enable GPIOC Clock*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC,ENABLE);
/*Configuration PA.5/6/7 on analog mode*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA,&GPIO_InitStructure);
/*Configuration PB.0/1 on analog mode*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_Init(GPIOB,&GPIO_InitStructure);
/*Configuration PC.0 on analog mode*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOC,&GPIO_InitStructure);
/*Check that HSI oscillator is ready*/
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
/*Enable ADC1 Clock*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
ADC_DeInit(ADC1);
/*ADC1 configuration*/
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 6;
ADC_Init(ADC1,&ADC_InitStructure);
/*ADC1 regular channel10 configuration*/
ADC_RegularChannelConfig(ADC1,ADC_Channel_5,1,ADC_SampleTime_4Cycles);
ADC_RegularChannelConfig(ADC1,ADC_Channel_6,2,ADC_SampleTime_4Cycles);
ADC_RegularChannelConfig(ADC1,ADC_Channel_7,3,ADC_SampleTime_4Cycles);
ADC_RegularChannelConfig(ADC1,ADC_Channel_8,4,ADC_SampleTime_4Cycles);
ADC_RegularChannelConfig(ADC1,ADC_Channel_9,5,ADC_SampleTime_4Cycles);
ADC_RegularChannelConfig(ADC1,ADC_Channel_10,6,ADC_SampleTime_4Cycles);
ADC_DMARequestAfterLastTransferCmd(ADC1,ENABLE);
/*Enable ADC1 DMA*/
ADC_DMACmd(ADC1,ENABLE);
/*Enable ADC1*/
ADC_Cmd(ADC1,ENABLE);
/*Wait until the ADC1 is ready*/
while(ADC_GetFlagStatus(ADC1,ADC_FLAG_ADONS) == RESET);
/*Start ADC1 Software Conversion*/
ADC_SoftwareStartConv(ADC1);
}
串口只能打印数组中第一个数据,而且还不正确,后面的数据都为0。 |
|