AnsweredAssumed Answered

stm32f103 ADC multichanel DMA STM32Cube_FW_F1_V1.0.0

Question asked by krasutski.denis on Apr 3, 2015
Latest reply on Apr 3, 2015 by krasutski.denis
Hello everyone,

I have trouble with getting ADC values over DMA. 
I saw example :STM3210E_EVAL\Examples\ADC\ADC_Sequencer and create project in MXCube with 13-ADC channels after generate code and launch project I am got only ch0 value other values set as zero. 
*Interrupt HAL_ADC_ConvCpltCallback has been occurred.

My initialization code:

001.void MX_DMA_Init(void)
002.{
003.  /* DMA controller clock enable */
004.  __HAL_RCC_DMA1_CLK_ENABLE();
005. 
006.  /* DMA interrupt init */
007.  HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 5, 0);
008.  HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn);
009.}
010. 
011./* ADC1 init function */
012.void MX_ADC1_Init(void)
013.{
014.ADC_ChannelConfTypeDef sConfig;
015. 
016. 
017./**Common config
018.*/
019.hadc1.Instance = ADC1;
020.hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
021.hadc1.Init.ContinuousConvMode = ENABLE;
022.hadc1.Init.DiscontinuousConvMode = DISABLE;
023.hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
024.hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
025.hadc1.Init.NbrOfConversion = 13;
026.   hadc1.Init.NbrOfDiscConversion = 13;
027.HAL_ADC_Init(&hadc1);
028. 
029. 
030./**Configure Regular Channel
031.*/
032.sConfig.Channel = ADC_CHANNEL_0;
033.sConfig.Rank = 1;
034.sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
035.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
036. 
037. 
038./**Configure Regular Channel
039.*/
040.sConfig.Channel = ADC_CHANNEL_1;
041.sConfig.Rank = 2;
042.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
043. 
044. 
045./**Configure Regular Channel
046.*/
047.sConfig.Channel = ADC_CHANNEL_3;
048.sConfig.Rank = 3;
049.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
050. 
051. 
052./**Configure Regular Channel
053.*/
054.sConfig.Channel = ADC_CHANNEL_6;
055.sConfig.Rank = 4;
056.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
057. 
058. 
059./**Configure Regular Channel
060.*/
061.sConfig.Channel = ADC_CHANNEL_7;
062.sConfig.Rank = 5;
063.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
064. 
065. 
066./**Configure Regular Channel
067.*/
068.sConfig.Channel = ADC_CHANNEL_8;
069.sConfig.Rank = 6;
070.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
071. 
072. 
073./**Configure Regular Channel
074.*/
075.sConfig.Channel = ADC_CHANNEL_9;
076.sConfig.Rank = 7;
077.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
078. 
079. 
080./**Configure Regular Channel
081.*/
082.sConfig.Channel = ADC_CHANNEL_10;
083.sConfig.Rank = 8;
084.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
085. 
086. 
087./**Configure Regular Channel
088.*/
089.sConfig.Channel = ADC_CHANNEL_11;
090.sConfig.Rank = 9;
091.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
092. 
093. 
094./**Configure Regular Channel
095.*/
096.sConfig.Channel = ADC_CHANNEL_12;
097.sConfig.Rank = 10;
098.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
099. 
100. 
101./**Configure Regular Channel
102.*/
103.sConfig.Channel = ADC_CHANNEL_13;
104.sConfig.Rank = 11;
105.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
106. 
107. 
108./**Configure Regular Channel
109.*/
110.sConfig.Channel = ADC_CHANNEL_14;
111.sConfig.Rank = 12;
112.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
113. 
114. 
115./**Configure Regular Channel
116.*/
117.sConfig.Channel = ADC_CHANNEL_15;
118.sConfig.Rank = 13;
119.HAL_ADC_ConfigChannel(&hadc1, &sConfig);
120. 
121. 
122.}
123. 
124. 
125. 
126.void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
127.{
128.RCC_PeriphCLKInitTypeDef PeriphClkInit;
129.GPIO_InitTypeDef GPIO_InitStruct;
130.if(hadc->Instance==ADC1)
131.{
132./* USER CODE BEGIN ADC1_MspInit 0 */
133. 
134. 
135./* USER CODE END ADC1_MspInit 0 */
136./* Peripheral clock enable */
137.__ADC1_CLK_ENABLE();
138.        
139.PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
140.PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
141.HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);       
142. 
143./**ADC1 GPIO Configuration
144.PC0 ------> ADC1_IN10
145.PC1 ------> ADC1_IN11
146.PC2 ------> ADC1_IN12
147.PC3 ------> ADC1_IN13
148.PA0-WKUP ------> ADC1_IN0
149.PA1 ------> ADC1_IN1
150.PA3 ------> ADC1_IN3
151.PA6 ------> ADC1_IN6
152.PA7 ------> ADC1_IN7
153.PC4 ------> ADC1_IN14
154.PC5 ------> ADC1_IN15
155.PB0 ------> ADC1_IN8
156.PB1 ------> ADC1_IN9
157.*/
158.GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
159.|GPIO_PIN_4|GPIO_PIN_5;
160.GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
161.       GPIO_InitStruct.Pull = GPIO_NOPULL;
162.HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
163. 
164. 
165.GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_6
166.|GPIO_PIN_7;
167.GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
168.HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
169. 
170. 
171.GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
172.GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
173.HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
174. 
175. 
176./* Peripheral DMA init*/
177. 
178.hdma_adc1.Instance = DMA1_Channel1;
179.hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
180.hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
181.hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
182.hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
183.hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
184.hdma_adc1.Init.Mode = DMA_CIRCULAR;
185.hdma_adc1.Init.Priority = DMA_PRIORITY_VERY_HIGH;
186.       
187.      HAL_DMA_DeInit(&hdma_adc1);
188.HAL_DMA_Init(&hdma_adc1);
189. 
190. 
191.__HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);
192. 
193. 
194./* System interrupt init*/
195.HAL_NVIC_SetPriority(ADC1_2_IRQn, 5, 0);
196.HAL_NVIC_EnableIRQ(ADC1_2_IRQn);
197./* USER CODE BEGIN ADC1_MspInit 1 */
198. 
199. 
200./* USER CODE END ADC1_MspInit 1 */
201.    }
202.}
203. 
204.void DMA1_Channel1_IRQHandler(void)
205.{
206./* USER CODE BEGIN DMA1_Channel1_IRQn 0 */
207. 
208. 
209./* USER CODE END DMA1_Channel1_IRQn 0 */
210.HAL_DMA_IRQHandler(&hdma_adc1);
211./* USER CODE BEGIN DMA1_Channel1_IRQn 1 */
212. 
213. 
214./* USER CODE END DMA1_Channel1_IRQn 1 */
215.}
216. 
217.void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc){
218.}
219. 
220.void HAL_ADC_ConvCpltCallback( ADC_HandleTypeDef * hadc){
221.    xSemaphoreGiveFromISR(_dma_ready_sem, NULL);
222.}
223. 
224.Start:
225.HAL_ADC_Start_DMA(&hadc1, (uint32_t*)table, 13);
226.//wait complete
227.//result:167, 0, 0, 0 ,0, 0, 0, 0 ,0, 0, 0, 0, 0


What else is required to run the ADC?
Or this problem in library?

Best Regards,
Krasutski Denis

Outcomes