cancel
Showing results for 
Search instead for 
Did you mean: 

multi ADC and DMA ==> memory problem

willdu87
Associate
Posted on March 05, 2013 at 16:57

Hello,

I need to measure 3 ADC channels in continuous, I use the STM32L151VB.

I use the DMA transfert, my firmware doesn't work property.

please see in attachment my source code

my problem is the  memory data  ''adcBuffer''

the DMA update only the case''0''

can you help me?

//-----------------------------------------------------------

  #include ''ADCuser.h''

  #include ''stm32l1xx_adc.h''

  #include ''stm32l1xx_dma.h''

//------------------------------------------------------------------------------

//------------------------------------------------------------------------------

static uint32_t adcBuffer[3] = {0};

//------------------------------------------------------------------------------

//------------------------------------------------------------------------------

//------------------------------------------------------------------------------

void ADC_init(void)

{

  ADC_InitTypeDef ADC_InitStructure;

  DMA_InitTypeDef DMA_InitStructure;

 

  RCC_HSICmd(ENABLE);

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

 

 

  /* DMA Channel1 Configuration ----------------------------------------------*/

  DMA_DeInit(DMA1_Channel1);

  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) &ADC1->DR ;

  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) adcBuffer;

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

  DMA_InitStructure.DMA_BufferSize = 3;

  DMA_InitStructure.DMA_PeripheralInc =  DMA_MemoryInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_PeripheralInc_Enable;

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;

  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);

 

  DMA_Cmd(DMA1_Channel1, ENABLE);

    

  /* ADC1 regular channel 7 configuration ************************************/

  ADC_InitStructure.ADC_Resolution = ADC_Resolution_10b;

  ADC_InitStructure.ADC_ScanConvMode = ENABLE;

  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

  ADC_InitStructure.ADC_ExternalTrigConv = 0;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_NbrOfConversion = 3;

  ADC_Init(ADC1, &ADC_InitStructure);

  ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_384Cycles);

  ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 2, ADC_SampleTime_384Cycles);

  ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 3, ADC_SampleTime_384Cycles);

 

  ADC_ContinuousModeCmd(ADC1, ENABLE);

  ADC_DMACmd(ADC1, ENABLE);

  ADC_Cmd(ADC1, ENABLE);

 

  while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);

 

  /* Wait until the ADC1 is ready */

  while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET);

  /* Start ADC1 Software Conversion */

  ADC_SoftwareStartConv(ADC1);

}

thanks a lot

2 REPLIES 2
Posted on March 05, 2013 at 17:33

This is bogus

  DMA_InitStructure.DMA_PeripheralInc =  DMA_MemoryInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_PeripheralInc_Enable;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; // It's still 16-bit wide, so HalfWord surely?

Would hazard you also need this prior to ADC_DMACmd()

  /* Enable the request after last transfer for DMA Circular mode */

  ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
willdu87
Associate
Posted on March 06, 2013 at 08:18

thanks a lot

perfect