Question
DMA not responding stm32f3 discovery
Posted on October 08, 2014 at 22:46
Hi,
I am trying to read a sequence of 2 values on ADC1 .I made the code without dma work then i decided to use the dma.I did some research and came out with those lines of code: When i debugg the buffer array keeps its defalut value. Any helpfull suggestions?#include ''stm32f30x.h''
#include ''stm32f30x_adc.h''
#include ''stm32f30x_gpio.h''
#include ''stm32f30x_rcc.h''
#include ''stm32f30x_dma.h''
__IO uint32_t TimingDelay = 10;
ADC_InitTypeDef ADC_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
int ConvValue = 0;
DMA_InitTypeDef DMA_InitStruct;
int DataBuffer[]={1,2};
void AdcConfig()
{TimingDelay = 10;
int calibration_value;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div1);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_PinLockConfig(GPIOA, GPIO_Pin_0);
GPIO_PinLockConfig(GPIOA, GPIO_Pin_1);
ADC_InitStruct.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStruct.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
ADC_InitStruct.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStruct.ADC_OverrunMode = DISABLE;
ADC_InitStruct.ADC_AutoInjMode = DISABLE;
ADC_InitStruct.ADC_NbrOfRegChannel = 2;
ADC_Init(ADC1,&ADC_InitStruct);
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1;
ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular ;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = 9;
ADC_CommonInit(ADC1, &ADC_CommonInitStructure);
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_1Cycles5);
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_1Cycles5);
ADC_VoltageRegulatorCmd(ADC1, ENABLE);
do {
TimingDelay--;
} while (TimingDelay > 0);
ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
ADC_StartCalibration(ADC1);
while (ADC_GetCalibrationStatus(ADC1) != RESET);
calibration_value = ADC_GetCalibrationValue(ADC1);
ADC_RegularChannelSequencerLengthConfig(ADC1, 2);
ADC_Cmd(ADC1, ENABLE);
}
void DmaConfig()
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/*-------------- Reset DMA init structure parameters values ------------------*/
DMA_InitStruct.DMA_PeripheralBaseAddr = ADC1->DR;
DMA_InitStruct.DMA_MemoryBaseAddr = DataBuffer;
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStruct.DMA_BufferSize = 2;
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
DMA_InitStruct.DMA_Priority = DMA_Priority_Low;
DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel1,&DMA_InitStruct);
DMA_Cmd(DMA1_Channel1,ENABLE);
}
int main(void) {
int i=0;
int j=0;
DmaConfig();
AdcConfig();
ADC_DMACmd(ADC1,ENABLE);
ADC_StartConversion(ADC1);
while (1) {
TimingDelay++;
i=DataBuffer[0];
j=DataBuffer[1];
}
return (0);
}
//j,i and Timing delay are just for debugging purpose.