6 years, 6 months ago.

I am using DMA ADC (HAL) and only get half of the values of the buffer

Hi,

I am programming an STM32F767ZI in order to use the ADC with DMA. Even though I'm writting the code with HAL libraries, I am using the Mbed compiler and the Mbed API.

Now I wrote a code that uses the DMA in order to get 2048 samples with the ADC and then calls the callback function. The problem is that when I try to access to the buffer, I find that only the even positions of the buffer are filled:

ADC_value[0] = value

ADC_value[1] = 0

ADC_value[2] = value

ADC_value[3] = 0

so on.

The configuration of the ADC is the following: (Actually the code configuration is from the STM32Cube examples) /media/uploads/Serga/capture.png /media/uploads/Serga/capture2.png

And this is the DMA configuration:

/media/uploads/Serga/capture3.png /media/uploads/Serga/capture4.png

The callback function:

/media/uploads/Serga/capture5.png

Do you know what this can happen? I guess is something about the configuration but I do not find out :(

If you need more information about the code, tell me.

Thank you.

Ok, I think I know why this happens. I initialize the buffer with 32 bits and the DMA uses the first 16 bits and the other 16 are empty, then for the next sample you have to move two times in the memory.

posted by Sergi Hernández 19 May 2018

1 Answer

6 years, 6 months ago.

I initialized the buffer with 16 bits, but the DMA accepts 32. So when I move through the buffer, each index moves 16 bits. Then if you want to go to the next value of the ADC you have to move twice (32 bits in total).

If you initialize the buffer with 32 bits instead of 16 bits, you only have to move one index to get the next value.

Accepted Answer

Assigned to Sergi Hernández 6 years, 6 months ago.

This means that the question has been accepted and is being worked on.