Skip to main content
AlaaM
Associate III
October 7, 2018
Question

Can I make each ADC channel ordered continuously when sampled using DMA?

  • October 7, 2018
  • 2 replies
  • 584 views

I'm sampling a single ADC with 3 channels using DMA.

Let's say the requested data size for each channel is 1024. So this is the code for starting DMA:

uint16_t buffer[1024*3];
HAL_ADC_Start_DMA(&hadc1, buffer, 1024*3);

Now when HAL_ADC_ConvCpltCallback() returns, I assume buffer is filled in the following way:

buffer[0]: channel 0

buffer[1]: channel 1

buffer[2]: channel 2

buffer[3]: channel 0

buffer[4]: channel 1

buffer[5]: channel 2

buffer[6]: channel 0

buffer[7]: channel 1

buffer[8]: channel 2

etc.

My question is: can I configure it to be automatically filled like the following:

buffer[0] = channel 1

buffer[1] = channel 1

buffer[2] = channel 1

buffer[3] = channel 1

...

buffer[1023] = channel 1

buffer[1024] = channel 2

buffer[1025] = channel 2

...

buffer[2047] = channel 2

buffer[2048] = channel 3

buffer[2049] = channel 3

...

buffer[3071] = channel 3

But still sampled in tandem (I just want the order to be consecutive for each channel).

Of course I can do it manually but my question is if there's a configuration to make it done automatically. I'm using CubeMX if that makes any difference...

    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    October 7, 2018

    >>My question is: can I configure it to be automatically filled like the following

    No

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    AvaTar
    Senior III
    October 8, 2018

    And such a large buffer would be a real waste of RAM.