请各位专家指点一下:DMA_InitTypeDef DMA_InitStructure; //DMA³õʼ»¯½á¹¹ÌåÉùÃ÷
void DMA_Config(void)
{
//ADC_InitTypeDef ADC_InitStructure;
//ADC_CommonInitTypeDef ADC_CommonInitStructure;
//DMA_InitTypeDef DMA_InitStructure;
//GPIO_InitTypeDef GPIO_InitStructure;
/* Enable ADC1, DMA2 and GPIO clocks ****************************************/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
DMA_DeInit(DMA2_Stream0);
/* DMA2 Stream0 channel2 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC1ConvertedValue;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = SAMPLEING_POINTS;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//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_Mode_Normal;//
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream0, ENABLE);
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);
}
void DMA2_Stream0_IRQHandler(void)
{
//if (DMA_GetFlagStatus(DMA2_Stream0, DMA_IT_TCIF0) != RESET)
if (DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0) != RESET)
{
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
//DMA_ClearFlag(DMA2_Stream0,DMA_FLAG_TCIF0);
//DMA_Cmd(DMA2_Stream0, DISABLE);
ADC_SoftwareStartConvCmd(ADC1,DISABLE);
DMA_Cmd(DMA2_Stream0, DISABLE);
DMARecFlag=1;
}
}
void DMAReConfig(void)
{
DMA_DeInit(DMA2_Stream0);
DMA_InitStructure.DMA_BufferSize = SAMPLEING_POINTS;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);
DMA_Cmd(DMA2_Stream0, ENABLE);
}
while (1)
{
#ifdef PRINT_ON_LCD
/* Display ADC converted value on LCD */
Display(max,max_position);
#endif
//ADC_Cmd(ADC1, ENABLE);
if (ADCStartFlag==1)
{
//DMA_Config();
//DMA2_Stream0->CNDTR = 0x00000064;
//ADC_Config();
//DMA_Cmd(DMA2_Stream0, ENABLE);
//ADC_DMACmd(ADC1, ENABLE);
//ADC_Cmd(ADC1, ENABLE);
ADC_SoftwareStartConvCmd(ADC1,ENABLE);//¿ªÊ¼²É¼¯
ADCStartFlag=0;
while(DMARecFlag==1) //´«Êä½áÊø£¬½øÐмÆËã
{
DMARecFlag=0;
//ADC_Cmd(ADC1, DISABLE);
//ADC_SoftwareStartConvCmd(ADC1,DISABLE);
//DMA_Cmd(DMA2_Stream0, DISABLE);
DMAReConfig();
// DMA_Config();
max=0;
for(i=0;i<SAMPLEING_POINTS ;i++)
{
if (ADC1ConvertedValue[i]>max)
{ max=ADC1ConvertedValue[i];
max_position=i;
}
}
j=max;
//break;
}
}
}
|