cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0 multi-channel ADC reading has DMA problem

Muhammed Güler
Senior III

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

1 ACCEPTED SOLUTION
4 REPLIES 4
Javier1
Principal

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

we dont need to firmware by ourselves, lets talk
Muhammed Güler
Senior III

it didn't work result is same

select yourself as best answer then

we dont need to firmware by ourselves, lets talk