我用STM32F401的adc1采样一个通道数据,然后通过dma传输到存储器,但是程序一直显示adc溢出,并且dma无动作,我查看dma的寄存器,显示都是0,似乎配置都没有写进寄存器,不知道哪里的问题,请大神帮忙看下,小弟不胜感激
#define ADC1_DR_Address ((uint32_t)0X4001204C)
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStruct;
RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_DMA2,ENABLE);
DMA_DeInit(DMA2_Stream0);
DMA_InitStruct.DMA_BufferSize=10;
DMA_InitStruct.DMA_Channel=DMA_Channel_0;
DMA_InitStruct.DMA_DIR=DMA_DIR_PeripheralToMemory;
DMA_InitStruct.DMA_FIFOMode=DMA_FIFOMode_Disable;
DMA_InitStruct.DMA_FIFOThreshold=DMA_FIFOThreshold_HalfFull;
DMA_InitStruct.DMA_Memory0BaseAddr=(uint32_t)&adc_buff[0];
DMA_InitStruct.DMA_MemoryBurst=DMA_MemoryBurst_Single;
DMA_InitStruct.DMA_MemoryDataSize=DMA_MemoryDataSize_HalfWord;
DMA_InitStruct.DMA_MemoryInc=DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_Mode=DMA_Mode_Circular;
DMA_InitStruct.DMA_PeripheralBaseAddr=/*(uint32_t)(ADC1_BASE+0x4C);*/ADC1_DR_Address;
DMA_InitStruct.DMA_PeripheralBurst=DMA_PeripheralBurst_Single;
DMA_InitStruct.DMA_PeripheralDataSize=DMA_PeripheralDataSize_HalfWord;
DMA_InitStruct.DMA_PeripheralInc=DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_Priority=DMA_Priority_High;
DMA_Init(DMA2_Stream0,&DMA_InitStruct);
DMA_Cmd(DMA2_Stream0,ENABLE);
}
void adc_init(void)
{
GPIO_InitTypeDef GPIO_SET; //GPIO config
ADC_InitTypeDef ADC_InitStruct;
ADC_CommonInitTypeDef ADC_CommonInitStruct;
GPIO_SET.GPIO_Mode=GPIO_Mode_AN; //Analog mode
GPIO_SET.GPIO_Speed=GPIO_Speed_100MHz; //Max speed is 50M
GPIO_SET.GPIO_OType=GPIO_OType_OD; //Open drain output
GPIO_SET.GPIO_PuPd=GPIO_PuPd_NOPULL; //Pull no
GPIO_SET.GPIO_Pin=GPIO_Pin_1;
GPIO_Init(GPIOA, &GPIO_SET); //Init GPIO
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
ADC_DeInit();
ADC_CommonInitStruct.ADC_DMAAccessMode=ADC_DMAAccessMode_1;
ADC_CommonInitStruct.ADC_Mode=ADC_Mode_Independent;
ADC_CommonInitStruct.ADC_Prescaler=ADC_Prescaler_Div2;
ADC_CommonInitStruct.ADC_TwoSamplingDelay=ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStruct);
ADC_InitStruct.ADC_ContinuousConvMode=ENABLE;
ADC_InitStruct.ADC_DataAlign=ADC_DataAlign_Right;
ADC_InitStruct.ADC_ExternalTrigConv=ADC_ExternalTrigConvEdge_None;
ADC_InitStruct.ADC_ExternalTrigConvEdge=ADC_ExternalTrigConvEdge_None;
ADC_InitStruct.ADC_NbrOfConversion=1;
ADC_InitStruct.ADC_Resolution=ADC_Resolution_12b;
ADC_InitStruct.ADC_ScanConvMode=ENABLE;
ADC_Init(ADC1,&ADC_InitStruct);
ADC_RegularChannelConfig(ADC1,ADC_Channel_1,1,ADC_SampleTime_15Cycles);
ADC_DMARequestAfterLastTransferCmd(ADC1,DISABLE);
ADC_DMACmd(ADC1,ENABLE);
ADC_Cmd(ADC1,ENABLE);
DMA_Config();
adc_delay(20000);
ADC_SoftwareStartConv(ADC1);
}
|