AnsweredAssumed Answered

stm32f3 DISCOVERY ADC DMA INT PROBLEM

Question asked by Lollo on Oct 31, 2014
Latest reply on Mar 2, 2016 by mcdowell.chris
Hi,
i have a problem with the dma adc conversion, the values of the conversion are correct but the interrupt is called only once. I would like to get an ongoing conversion.

main.c
001./* Includes ------------------------------------------------------------------*/
002.#include "main.h"
003. 
004.#define ADC1_DR_Address ((uint32_t)0x50000040)
005.#define SIZE    4
006.#define CHANNEL 4
007. 
008.__IO uint16_t calibration_value = 0;
009.__IO uint32_t TimingDelay = 0;
010.bool flag_ADCDMA_TransferComplete = false;
011. 
012.void Delay(__IO uint32_t nTime);
013.void TimingDelay_Decrement(void);
014.void ADC_Configure(void);
015. 
016. 
017.__IO uint16_t ADC_Val[4];
018.uint16_t temp[4];
019.  
020./**
021. * @brief  Main program.
022. * @param  None
023. * @retval None
024. */
025.int main(void)
026.
027.  RCC_ClocksTypeDef     RCC_Clocks;
028.     
029.  /* SysTick end of count event each 10ms */
030.  RCC_GetClocksFreq(&RCC_Clocks);
031.  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); 
032.  ADC_Configure();
033. 
034.   
035.  while(1)
036.  {
037.    //memcpy(&temp[0],ADC_Val,5);   
038.     
039.    while(flag_ADCDMA_TransferComplete == false);
040.    for(uint8_t i=0; i<4; i++)
041.    {
042.      temp[i]=ADC_Val[i]/4;
043.    }   
044.    printf("%d,%d,%d,%d\n\r",temp[0],temp[1],temp[2],temp[3]);
045.    flag_ADCDMA_TransferComplete = false;
046.  }
047.   
048.}
049.   
050. 
051. 
052. 
053. 
054. 
055. 
056.void ADC_Configure(void)
057.{
058.  GPIO_InitTypeDef      GPIO_InitStructure;
059.  ADC_InitTypeDef       ADC_InitStructure;
060.  ADC_CommonInitTypeDef ADC_CommonInitStructure;
061.  DMA_InitTypeDef       DMA_InitStructure;
062.  NVIC_InitTypeDef      NVIC_InitStructure;
063. 
064.     
065.  /* GPIOA GIPOF Periph clock enable */
066.  /* Enable ADC1 clock */
067.  /* DMA configuration */
068.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
069.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);
070.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);
071.  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
072. 
073.  //------------------------------------------------------------------------
074.   
075.  /* Configure ADC Channel7 as analog input */
076.  /* ADC1 per:
077.  *     PA1 -> ADC1_IN2
078.  *     PA2 -> ADC1_IN3
079.  *     PA3 -> ADC1_IN4
080.  *     PF4 -> ADC1_IN5
081.  */
082.  /* PA1 PA2 PA3 */
083.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 ;
084.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
085.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
086.  GPIO_Init(GPIOA, &GPIO_InitStructure);
087.   
088.  /* PF4 */
089.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;
090.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
091.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
092.  GPIO_Init(GPIOF, &GPIO_InitStructure);  
093.   
094.  //------------------------------------------------------------------------
095.   
096.  /* Configure the ADC clock */
097.  RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2);   
098. 
099.  ADC_StructInit(&ADC_InitStructure);
100. 
101.  /* Calibration procedure */ 
102.  ADC_VoltageRegulatorCmd(ADC1, ENABLE);
103.   
104.  ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
105.  ADC_StartCalibration(ADC1);
106.      
107.  ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;                                                                   
108.  ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;                   
109.  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;            
110.  //ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;
111. ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular;            
112.  ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;         
113.  ADC_CommonInit(ADC1, &ADC_CommonInitStructure);
114.   
115.  while(ADC_GetCalibrationStatus(ADC1) != RESET );
116.  calibration_value = ADC_GetCalibrationValue(ADC1); 
117.   
118.   
119.  ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
120.  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
121.  ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;        
122.  ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
123.  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
124.  ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;  
125.  ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable; 
126.  ADC_InitStructure.ADC_NbrOfRegChannel = CHANNEL;
127.  ADC_Init(ADC1, &ADC_InitStructure);
128.   
129.  ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1,ADC_SampleTime_19Cycles5);
130.  ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 2,ADC_SampleTime_19Cycles5);
131.  ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 3,ADC_SampleTime_19Cycles5);
132.  ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 4,ADC_SampleTime_19Cycles5);
133.   
134.  //------------------------------------------------------------------------
135. 
136.  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR;
137.  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC_Val; 
138.  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; 
139.  DMA_InitStructure.DMA_BufferSize = SIZE;
140.  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
141.  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
142.  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;   // 16 bit
143.  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;   // 16 bit
144.  //DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
145.  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
146.  DMA_InitStructure.DMA_Priority = DMA_Priority_High;
147.  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
148.  DMA_Init(DMA1_Channel1, &DMA_InitStructure);
149. 
150.  //------------------------------------------------------------------------
151. 
152.  /* Enable DMA1 channel1 IRQ Channel */
153.  NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
154.  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
155.  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
156.  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
157.  NVIC_Init(&NVIC_InitStructure);
158.   
159.    /* Enable DMA1 Channel1 Transfer Complete interrupt */
160.  DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE); 
161. 
162.  //------------------------------------------------------------------------
163.    
164.  // abilita il canale dma per ADC1
165.  DMA_Cmd(DMA1_Channel1, ENABLE);
166.  // abilita adc1 con dma
167.  ADC_DMACmd(ADC1, ENABLE);
168. 
169.  /* Enable ADC1 */
170.  ADC_Cmd(ADC1, ENABLE);
171.  
172.  /* wait for ADRDY */
173.  while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY));
174.   
175.  /* Start ADC1 Software Conversion */
176.  ADC_StartConversion(ADC1);  
177.   
178.}
179. 
180. 
181. 
182./**
183. * @brief  Inserts a delay time.
184. * @param  nTime: specifies the delay time length, in 10 ms.
185. * @retval None
186. */
187.void Delay(__IO uint32_t nTime)
188.{
189.    TimingDelay = nTime;
190.  
191.    while(TimingDelay != 0);
192.}
193.  
194./**
195. * @brief  Decrements the TimingDelay variable.
196. * @param  None
197. * @retval None
198. */
199.void TimingDelay_Decrement(void)
200.{
201.    if (TimingDelay != 0x00)
202.    {
203.        TimingDelay--;
204.    }
205.}
and stm32f30x_it.c
01.void SysTick_Handler(void)
02.{
03.  TimingDelay--;
04.}
05. 
06. 
07./**
08.  * @brief  This function handles DMA Transfer Complete interrupt request.
09.  * @param  None
10.  * @retval None
11.  */
12.void DMA1_Channel1_IRQHandler(void)
13.{
14.  DMA_ClearFlag(DMA1_IT_TC1);
15.  flag_ADCDMA_TransferComplete = true;
16.}

Outcomes