STM32 ADC DMA. When MCU is informed about end of ADC?

Viewed 1091

I use ADC with DMA (STM32F4, ide STM32CubeIDE) and I think that I understand how it works but still have one dilema. From my understanding MCU is called only when DMA transfer is completed, basically MCU go into this function when DMA ADC is finished

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

Is that right?

So if this is true, I have next dilema: for example adc_clock is 10MHz, sample time is 480 adc_cycles, 12 bit adc resolution. adc_sample_period = 1/10Mhz * (480 + 12 + 3) = 49.5uS. That mean MCU will go into HAL_ADC_ConvCpltCallback() every 49.5uS ??? For my perspective that is hard intensive, especially in bigger projects. Did anyone have idea how to solve this "problem"? I want to read ADC results for example every 1mS but also want to implement DMA into ADC. Any idea is welcome

2 Answers

Read the uC documentation - do not start from the "magic" HAL functions.

1ms period between the the ADC conversions is absolutely nothing. I have many projects where I use double or triple ADC modes with resulting sampling rate of 18MSPS.

Generally speaking if you want poor, slow, inefficient and working "by accident" code - use HAL. Otherwise learn your hardware and use registers instead.

This is how I solve this problem: I change DMA configuration. DMA was configurated to work in circular mode, that mean when ADC finish one conversion DMA store data and MCU is notified via

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

Basically MCU was notified every 49.5uS and for my purpose that was too intensive (I need ADC result every 1mS). I create timer which is used to indicate ADC when need to start sample and with DMA in normal mode (ADC will do only 1 measurement) that solve my problem. Every 1mS got result from ADC. So trick was in DMA modes (circular/normal mode).

Related