cancel
Showing results for 
Search instead for 
Did you mean: 

How to use properly ADC to DMA, HAL_ADC_Start_DMA(&hadc1, (uint32_t*)array, 1000);

MNapi
Senior III

I want to make 1000 scans, I have the adc running at 1.5 Msps, 12 bit resolution on 180 Mhz Nucelo board.

when I put HAL_ADC_Start_DMA(&hadc1, (uint32_t*)array, 1000); in main(); it would run only once

I want a continues scan, it seams to be doing just that in while(); loop

but I think that I need some delay like

while();

{

HAL_ADC_Start_DMA(&hadc1, (uint32_t*)array, 1000);

HAL_Delay(1);

}

Fist question does it indeed take 1000 scans and puts in the array[1000];

Second how to properly implement it so I have access to data in array all the time.

And it look like I have to declare

uint32_t array[1000];

anything else like uint16_t array[1000]; wouldn't work

I am new to this and I do not understand fully all the code, what they do.

2 REPLIES 2
S.Ma
Principal
  1. when using data arrays accessed by DMA, you need a #pragma at the declaration line to tell the linker it is 32 bit aligned address. Compiler dependent. If don't know, check USB example, it's using DMA so you'll find the answer to the question
  2. Double the buffer size and get a DMA half transfer interrupt so you can process your first 1000 samples while the next 1000 are bering processed and you reprogram the DMA to loop back. (double buffering). No delay.

would you know if it is indeed 1.5 Msps, I am using Cube MX and it says there 12 bit resolution takes 15 clock cycles

But at the bottom there is also sampling time, it is a little confusing I have sampling time 3 cycles.

would the actual speed be 15 + 3 clock cycles. or it is independent.

or the sampling time is time to get the adc data already sitting in the buffer.

the highest speed is supposed to be 2.5 Msps but for lowest resolution 6 bits