cancel
Showing results for 
Search instead for 
Did you mean: 

ADC with DMA triggered by software

smrtkai
Senior
Posted on June 22, 2016 at 15:32

Hi,

I would like to trigger the ADC conversion with DMA via a software command. I tried several configurations but I haven't succeed yet. The simplest thing would be to push a button and the ADC starts converting and after 10 conversion the DMA complete callback is invoked.

This is what I think should be the right correct, but does not work. I have configured my code using STM32CubeMX.

Scan Conversion: Disabled (Only one channel should be converted)

Continuous Conversion Mode: Enabled (Convert until DMA is full)

DMA Continuous Requests: Disabled (Should be triggered via software)

Using the following commands the conversion works one time (DMA callback is invoked). How can I restart the ADC conversion so that the callback is invoked again? I tried to stop the ADC and start it again. But it does not work.

  HAL_ADC_Start(&hadc1);

  HAL_ADC_Start_DMA(&hadc1, (uint32_t*) input_data, 10);  

Can anyone?
5 REPLIES 5
slimen
Senior
Posted on June 22, 2016 at 16:08

Hi smrtkai,

I recommend you start with ''ADC_RegularConversion_DMA'' example available in the Firmware package which describes how to use the ADC and DMA to transfer continuously converted data from ADC to memory.

For Example for STM32F4, you can find the example under : STM32Cube_FW_F4_V1.12.0\Projects\STM32F4-Discovery\Examples\ADC\ADC_RegularConversion_DMA

Regards

AvaTar
Lead
Posted on June 22, 2016 at 16:09

I did something similar, only triggering the ADC from the SysTick interrupt instead of a push button (and probably EXTI interrupt).

However, based on the SPL. Can't help you with Cube/HAL ...

smrtkai
Senior
Posted on June 23, 2016 at 14:01

I have running code with regular ADC conversion and a continous DMA transfer. But what do I have to change to make it not continuous. But instead triggered by some code. For example push button, external interrupt or an FreeRTOS timer.

I have tried quite some configurations but nothing works as expected. Does anyone know how to change the adc configuration? Or could someone provide some example code? That would be great.
mark239955_stm1
Associate II
Posted on June 24, 2016 at 03:54

This is actually explained in the reference manual.  The RM is very complete, but can be a bit hard to read.  Roughly:

1. Configure the ADC and put it under DMA control.

2. Configure a DMA stream to work with the ADC, including setting it to do 10 transactions only.

3. Configure a timer to trigger the ADC at whatever rate you want the samples taken, but don't start the timer yet.

4. Enable the ADC and DMA.

5. When you're ready, start the timer and wait for DMA to interrupt.  Stop the timer in the DMA interrupt.

smrtkai
Senior
Posted on June 27, 2016 at 10:07

Thank you.