cancel
Showing results for 
Search instead for 
Did you mean: 

I want to Configure 16 adc in DMA mode (Stm32f410RB microcontoller)

Lkhod.1
Associate II

i use nucleo - f410RB board , i want to configure 16 adc channel continuous conversion and continuous scan mode, we use cube mx for adc dma code generation , but generated code not working , so please help me how to configure adc in dma mode so adc is working in nucleo-f410rb board so

please help me

thanks

1 REPLY 1
GwenoleB
ST Employee

Dear @Lkhod.1​ ,

Using CubeMX you will configure ADC & DMA together in order to use SCAN mode on 16 ADC's channels.

First of all, check you have enabled each channel.

Then, go to Parameters Settings tab and check that your configuration is the same as below:

0693W00000FAMHsQAP.png 

0693W00000FAMJjQAP.pngThen, after it should appear 16 Rank sections, for each of them, select the input channel and the Sampling Time. If you decide to not choose a specific Sampling Time, 3 Cycles option is selected.

Go on DMA Settings tab (always in ADC1 parameters) and click on add button. As you want to convert in continuous mode, DMA will work as a circular buffer so select Mode Circular. The Addresses of your memory need to be increment automatically to fill your array. For that enables Memory Increment Address by checking the box and your data width will be a Word (or half-word 16-bit if you want).

0693W00000FAMLuQAP.png 

Now your ADC and DMA are correctly configured. Now it's required to add some lines of code to start ADC and DMA.

First, create an array of 16 elements of uint32_t type (or uint16_t if you choose half-word). I am using a define for the size of array defined as below:

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define NUMBER_OF_CONVERSION 16
/* USER CODE END PD */

/* USER CODE BEGIN PV */
uint32_t ADC1_Results[NUMBER_OF_CONVERSION];
/* USER CODE END PV */

Now, start ADC with DMA by using:

/* USER CODE BEGIN 2 */
  HAL_ADC_Start_DMA(&hadc1, ADC1_Results, NUMBER_OF_CONVERSION);
  /* USER CODE END 2 */

The first parameter is your ADC Instance followed by your array name and the last is the size of the array. Calling this function will start converting is continuous mode and DMA will transfer each conversion result from ADC->DR register to your array and will loop each 16 conversions.

To check if it's working, enter in debug mode and add your ADC1_Results array in Live Expressions tab. You will see that ADC and DMA working continuously and each element of your array is corresponding to one channel conversion.

Please let me know if it's working on your side.

Best Regards,

Gwénolé