cancel
Showing results for 
Search instead for 
Did you mean: 

Adc3 Dma no value (STM32F4xx)

zerbales
Associate
Posted on January 13, 2014 at 15:56

I' m trying to save two ADC3 values in memory using dma, but nothing is stored in the memory, someone can help me, my code is:

int main(void)

{

 

    //Configuration of the ADC channels used

   ADC_Config();

  

   

    ADC_SoftwareStartConv(ADC3);

    printf(''start'');

 

    while(1)

  {

      //ADC_val=ADCConvertedValues[0];

    if (ADCConvertedValues[1] != 0xFFFF)

    {

      printf(''%X %X \n'', ADCConvertedValues[0], ADCConvertedValues[1]);

      //ADCConvertedValues[1] = 0xFFFF;

    }

  }

 

}

static void ADC_Config(void)

{

  ADC_InitTypeDef       ADC_InitStructure;

  ADC_CommonInitTypeDef ADC_CommonInitStructure;

  DMA_InitTypeDef       DMA_InitStructure;

 

  /* Enable peripheral clocks *************************************************/

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);

 

  /* DMA2_Stream0 channel0 configuration **************************************/

  DMA_DeInit(DMA2_Stream0);

  DMA_InitStructure.DMA_Channel = DMA_Channel_2;// Channel 0 as mentionned in the datasheet ??

  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC3->DR;// Address of ADC3 peripheral ??

  DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADCConvertedValues[0];// pointer on my data

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;// From ADC to memory

  DMA_InitStructure.DMA_BufferSize = 3;// 2 data to bring back (2 ANA input)

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;// No incrementation of peripheral, always read at the same address

  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_FIFOMode = DMA_FIFOMode_Disable;

  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;

  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;

  DMA_Init(DMA2_Stream0, &DMA_InitStructure);

  /* DMA2_Stream0 enable */

  DMA_Cmd(DMA2_Stream0, ENABLE);

 

  /* ADC Common Init **********************************************************/

  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;

  ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;

  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

  ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;

  ADC_CommonInit(&ADC_CommonInitStructure);

 

  /* ADC3 Init ****************************************************************/

  ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b;

  ADC_InitStructure.ADC_ScanConvMode = ENABLE;

  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

  ADC_InitStructure.ADC_ExternalTrigConvEdge =ADC_ExternalTrigConvEdge_None ;

  ADC_InitStructure.ADC_ExternalTrigConv =ADC_ExternalTrigConv_T1_CC1 ;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_NbrOfConversion = 2;

  ADC_Init(ADC3, &ADC_InitStructure);

 

  /* ADC3 regular channel configuration ******************************/

  ADC_RegularChannelConfig(ADC3, ADC_Channel_9, 1, ADC_SampleTime_480Cycles);//PF3

  ADC_RegularChannelConfig(ADC3, ADC_Channel_14, 2, ADC_SampleTime_480Cycles);//PF4

 

 

  /* Enable DMA request after last transfer (Single-ADC mode) */

  ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE);

 

  ADC_DMACmd(ADC3, ENABLE);

 

   **************************************************************/

  ADC_Cmd(ADC3, ENABLE);

}

#selective-cut-n-paste
2 REPLIES 2
Posted on January 13, 2014 at 16:25

someone can help me, my code is:

Looks a bit familiar, but post ALL of it, I have better things to do than recreate the half that's missing.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zerbales
Associate
Posted on January 16, 2014 at 09:46

Yes i follow another example, but i' ve resolved i forget the GPIO  configuration.