cancel
Showing results for 
Search instead for 
Did you mean: 

Help with ADC + DMA integration.

nortex
Associate

Hello.

I want to integrate ADC with DMA, and calculate the average count of all convertions.

I'm using the following code:

In adc.c:

```

if(HAL_ADC_PollForConversion(&hadc1, 10) == HAL_OK) {
uint16_t value = HAL_ADC_GetValue(&hadc1);
USART_Send("%.3f", value);
HAL_ADC_Start(&hadc1);
}

```

In main.c:

```

HAL_ADC_Start_DMA(&hadc1, (uint8_t*) AVG_BUF, AVG_BUF_SIZE);

```

 

However HAL_ADC_GetValue() seems to not use DMA.

I want it to explicitely use DMA to read.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

HAL_ADC_Start_DMA will put values into the buffer you specify, in this case AVG_BUG. So that is where you should read values from. Implement the HAL_ADC_ConvCpltCallback call to read out the values after they're all transferred. Refer to the documentaiton in stm32f4xx_hal_adc.c:

(++) ADC conversion with transfer by DMA: (+++) Activate the ADC peripheral and start conversions using function HAL_ADC_Start_DMA() (+++) Wait for ADC conversion completion by call of function HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback() (these functions must be implemented in user program) (+++) Conversion results are automatically transferred by DMA into destination variable address. (+++) Stop conversion and disable the ADC peripheral using function HAL_ADC_Stop_DMA()

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

1 REPLY 1
TDK
Guru

HAL_ADC_Start_DMA will put values into the buffer you specify, in this case AVG_BUG. So that is where you should read values from. Implement the HAL_ADC_ConvCpltCallback call to read out the values after they're all transferred. Refer to the documentaiton in stm32f4xx_hal_adc.c:

(++) ADC conversion with transfer by DMA: (+++) Activate the ADC peripheral and start conversions using function HAL_ADC_Start_DMA() (+++) Wait for ADC conversion completion by call of function HAL_ADC_ConvCpltCallback() or HAL_ADC_ConvHalfCpltCallback() (these functions must be implemented in user program) (+++) Conversion results are automatically transferred by DMA into destination variable address. (+++) Stop conversion and disable the ADC peripheral using function HAL_ADC_Stop_DMA()

 

If you feel a post has answered your question, please click "Accept as Solution".