Question
stm32 adc with dma
Posted on July 08, 2013 at 11:06
I am using stm32f100, i using it to control the motor . i am using 3 adc channels to read back-emf, dumping the adc-dr values in dma. am i doing it correct.........plz suggest me.
here's the code here i using an array of size 3 and dumping the value of each array in separate variable using dma. assume variables are declaredint ADCConvertedValue[3];//==Configure DMA1 - Channel1==DMA_DeInit(DMA1_Channel1); //Set DMA registers to default valuesDMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //Address of peripheral the DMA must map toDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) & ADCConvertedValue; //Variable to which ADC values will be storedDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;DMA_InitStructure.DMA_BufferSize = 3; //Buffer size (2 because we using two channels)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); //Initialise the DMADMA_Cmd(DMA1_Channel1, ENABLE); //Enable the DMA1 - Channel1////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////==Configure ADC1 - Channel 14 and Channel 15==ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;ADC_InitStructure.ADC_ScanConvMode = ENABLE;ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;ADC_InitStructure.ADC_NbrOfChannel = 3; //We using two channelsADC_Init(ADC1, &ADC_InitStructure); //Initialise ADC1//Setup order in which the Channels are sampled....ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_55Cycles5);ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_55Cycles5);ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_55Cycles5);ADC_DMACmd(ADC1, ENABLE); //Enable ADC1 DMAADC_Cmd(ADC1, ENABLE); //Enable ADC1//==Calibrate ADC1==//Enable ADC1 reset calibaration registerADC_ResetCalibration(ADC1);while (ADC_GetResetCalibrationStatus(ADC1)); //Check the end of ADC1 reset calibration register//Start ADC1 calibarationADC_StartCalibration(ADC1);while (ADC_GetCalibrationStatus(ADC1)); //Check the end of ADC1 calibration void main(){a=ADCConvertedValue[0]; b=ADCConvertedValue[1]; c=ADCConvertedValue[2];} #discovery #dma #stm32 #adc