AnsweredAssumed Answered

stm32 adc with dma

Question asked by k_dash on Jul 8, 2013
Latest reply on Jul 9, 2013 by k_dash
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 declared

int ADCConvertedValue[3];
//==Configure DMA1 - Channel1==
DMA_DeInit(DMA1_Channel1); //Set DMA registers to default values
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //Address of peripheral the DMA must map to
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) & ADCConvertedValue; //Variable to which ADC values will be stored
DMA_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 DMA
DMA_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 channels

ADC_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_Cmd(ADC1, ENABLE); //Enable ADC1

//==Calibrate ADC1==

//Enable ADC1 reset calibaration register
while (ADC_GetResetCalibrationStatus(ADC1)); //Check the end of ADC1 reset calibration register

//Start ADC1 calibaration
while (ADC_GetCalibrationStatus(ADC1)); //Check the end of ADC1 calibration 

void main()