本帖最后由 小猫薄薄 于 2014-3-19 16:52 编辑
用的是stm32f051的板子
adc_dma初始化如下
#include "adc.h"
#define ADC1_DR_Address 0x40012440//
__IO uint16_t RegularConvData_Tab;//
void ADC1_DMA_Init(void)
{
//RegularConvData_Tab= 2473;
ADC_InitTypeDef ADC_InitStruct;
DMA_InitTypeDef DMA_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
ADC_DeInit(ADC1);//
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);//
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); /* DMA1 clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;//
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL ;//
GPIO_Init(GPIOA, &GPIO_InitStruct); //
/* DMA1 Channel1 Config */
DMA_DeInit(DMA1_Channel1);//
DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address;//
DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)&RegularConvData_Tab;//
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC
DMA_InitStruct.DMA_BufferSize =4;//
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;//
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//ÈÓÐbyte£¬halfword£¬word
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;//
DMA_InitStruct.DMA_Priority = DMA_Priority_High;//
DMA_InitStruct.DMA_M2M = DMA_M2M_Disable
DMA_Init(DMA1_Channel1, &DMA_InitStruct);
DMA_Cmd(DMA1_Channel1, ENABLE);//
ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular);//
ADC_DMACmd(ADC1, ENABLE);
ADC_StructInit(&ADC_InitStruct);//
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;//
ADC_InitStruct.ADC_ContinuousConvMode = ENABLE; //
ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;//
ADC_InitStruct.ADC_ScanDirection = ADC_ScanDirection_Backward;//
ADC_Init(ADC1, &ADC_InitStruct);
ADC_ChannelConfig(ADC1, ADC_Channel_1 , ADC_SampleTime_55_5Cycles); //
ADC_GetCalibrationFactor(ADC1);//
ADC_DMACmd(ADC1, ENABLE);//
ADC_Cmd(ADC1, ENABLE); //
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN)); //
ADC_StartOfConversion(ADC1);//
}
|