Skip to main content
Muhammed Güler
Senior III
May 5, 2022
Solved

STM32L0 multi-channel ADC reading has DMA problem

I am trying to read 2 channel ADC with STM32L011F4.

My ADC and DMA settings in cubemx are as follows0693W00000NpJS3QAN.png0693W00000NpJSIQA3.png 

my problem is that the DMA only returns the low 8 bit of the last channel.

uint16_t ADC_Reads[2] = {0};
 
	while (1)
	{
		HAL_ADC_Start_DMA(&hadc,(uint32_t *)ADC_Reads,2);
		HAL_Delay(1000);
	}

When I write the following code in the DMA IRQ handler, I can read the values.

uint16_t ADCReads[2];
char i=0;
void DMA1_Channel1_IRQHandler(void)
{
 /* USER CODE BEGIN DMA1_Channel1_IRQn 0 */
ADCReads[i] = hadc.Instance->DR;
	i = 1-i;
 /* USER CODE END DMA1_Channel1_IRQn 0 */
 HAL_DMA_IRQHandler(&hdma_adc);
 /* USER CODE BEGIN DMA1_Channel1_IRQn 1 */
 
 /* USER CODE END DMA1_Channel1_IRQn 1 */
}

EWARM live watch screen looks like below

0693W00000NpJW0QAN.png

This topic has been closed for replies.

4 replies

Javier1
Principal
May 5, 2022

Lots of people had issues wth this, including me.

Try this out:

HAL_ADC_Start_DMA(&hadc,(uint32_t *)ADC_Reads, sizeof(ADC_Reads)/sizeof(ADC_Reads[0]));
 
 
or
 
 
HAL_ADC_Start_DMA(&hadc,(uint16_t *)ADC_Reads, sizeof(ADC_Reads)/sizeof(ADC_Reads[0]));

hit me up in https://www.linkedin.com/in/javiermuñoz/
Muhammed Güler
Senior III
May 6, 2022

it didn't work result is same

Javier1
Principal
May 9, 2022

select yourself as best answer then

hit me up in https://www.linkedin.com/in/javiermuñoz/