Skip to main content
JRobe.2
Associate III
June 1, 2021
Solved

I am using a timed scan of four ADC channels and DMA in circular mode to place them in an array. My goal is to place each of the four ADC results in a separate 1024-element circular buffer using DMA or DMAMUX. Does anyone have some guidance?

  • June 1, 2021
  • 3 replies
  • 2430 views

..

This topic has been closed for replies.
Best answer by Javier1

the DMA automatically interleaves the ADC values.

It will fill (as a circular buffer if configured that way ) the array you pass as an argument, no matter the length untill you stop it.

uint32_t ADCReadings[1024];
 
//DMA will take hadc1 readings(interleaving channels) and store them inside ADCReadings array, the circular buffer created has legth 1024
 
HAL_ADC_Start_DMA(&hadc1, (uint32_t*) ADCReadings, 1024);

DMA will fill ADCReadings as follows: (if 4 channels from adc are activated)

  1. ADCReadings[0]= value from 1st channel
  2. ADCReadings[1]= value from 2nd channel
  3. ADCReadings[2]= value from 3rd channel
  4. ADCReadings[3]= value from 4rd channel
  5. ADCReadings[4]= value from 1st channel
  6. ADCReadings[5]= value from 2nd channel
  7. ADCReadings[6]= value from 3rd channel
  8. ADCReadings[7]= value from 4rd channel

.............

1024.ADCReadings[1023]= value from 4rd channel

3 replies

Javier1
Principal
June 1, 2021

you mean this?

https://www.youtube.com/watch?v=0jKtgP4OYvU

follow that video with 4 ADC inputs and create your DMA destination memory array as long as you want.

That channel is Great for learning stm32

hit me up in https://www.linkedin.com/in/javiermuñoz/
JRobe.2
JRobe.2Author
Associate III
June 1, 2021

Yes. That method should work. I can index into the interleaved circular buffer as a 4 by 1024 array. The DMA will handle the wrap around...

TDK
June 1, 2021

You cannot put each channel into a separate location via DMA. They will all be interleaved and you'll need to move them around in memory as you require.

Probably better to rework your code to not require separate buffers.

"If you feel a post has answered your question, please click ""Accept as Solution""."
JRobe.2
JRobe.2Author
Associate III
June 1, 2021

A single circular 4 x 1024 array would be ideal...

TDK
June 1, 2021

Oh, so all results in the same buffer? Look at DMA ADC examples in the cube repository of the chip you're using. Or Javier's link. HAL_ADC_Start_DMA does this exactly.

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

HAL_ADC_Start_DMA takes the length of your buffer as the last argument. Change it from 4 to whatever you want.

"If you feel a post has answered your question, please click ""Accept as Solution""."
JRobe.2
JRobe.2Author
Associate III
June 1, 2021

Ok. Perfect. Thanks.

This won't affect the ADC channel scan since that is an ADC parameter...