Skip to main content
CSand
Senior
June 16, 2026
Solved

ADC1 GPDMA1 4 chanels - how to config and run ?

  • June 16, 2026
  • 10 replies
  • 121 views

Hi ,
I have a board that has a STM32H562xxx , I have 4 analog inputs mapped on ADC1 IN1, IN14, IN15 and IN18 single ended … ( PA1, PA2, PA3,PA4 ), TRGO TIM8 
I have DCACHE1 disabled 
HAL_ADC_ConvHalfCpltCallback - gives a flag the cvt is completed
I have a uint16_t dmaBuffer[4]

When I run it the variable dmaBuffer[0..2] have values ~220 with small oscillations and only dmaBuffer[3]  with correct values from ADC1

It’s the first time I used this board and 1st to have CACHE … otherwise I eventually disabled it.
Can anyone help ? What info do I need to provide so I get little help make this work ?

Thanks
Cristian

 

Best answer by CSand

 

Well it just went into my mind that I should move the potentiometer that is read correctly to a different channel - and the good reading moved on that channel … 🤣

It looks that the issue was actually a bad GND connection on the connector used to supply all the other pot’s. The pot that was working has independent/different supply circuit…  
I suspect wen I used the multimeter I made a stronger GND connection with the probe - so I measured good values! But when I tucked the probe away ...

 

Yet it is another lesson to trust myself much more !!

Thanks for support!

 

10 replies

Ozone
Principal
June 16, 2026

I use neither the H7 nor Cube/HAL.

> HA:_ADC_ConvHalfCpltCallback - gives a flag the cvt i completed

This supposedly means half-completed, and IMHO would explain it.


When using the ADC in a multchannel setup, I usually configure a DMA buffer for multiple samples at once (#of channels x <n>), but this depends on the project.

CSand
CSandAuthor
Senior
June 16, 2026

I edited the post to correct the typo  HA:_ADC I’m sorry …
@Ozone  
… dmaBuffer[4] 
Ok, “Half” may be not ok … 
Regards,

Ozone
Principal
June 16, 2026

Not just a typo, I guess, but the wrong callback.

My code is often derived from the “old” SPL,  mostly a thinly veiled register level access using ST device header defines.

ST’s DMA controllers use to have a “half-complete” interrupt option, which I never use or used.
I would recommend to check your respective code, and modify it to “TC” (transmission complete).
Not sure how to do that in Cube/HAL, though ...

CSand
CSandAuthor
Senior
June 16, 2026

I’m so busy to resolve this … you are correct …It’s wrong callback …
Let me intervene , add correct callback then back here 

CSand
CSandAuthor
Senior
June 16, 2026

Well , it does not matter what callback it is , the callback I’m using just to flag the buffer has fresh values …
 

Ozone
Principal
June 16, 2026

Yes, of course.

> When I run it the variable dmaBuffer[0..2] have values ~220 with small oscillations and only dmaBuffer[3]  with correct values from ADC1

Not sure how you got to that point.
But I recommend to either apply known and different voltage levels to all 4 AINs at once, or to one at a time and GND to the others.
This way you can validate that your timer - ADC - DMA sequence works correctly.
I use to set a breakpoint in the DMA TC interrupt for this purpose, but a respective callback should do as well.

Keep in mind that DMA keeps overwriting your buffer values as soon as the next sampling sequence starts.
This is fine for static a validation with static inputs, but probably not for the actual application.

CSand
CSandAuthor
Senior
June 17, 2026

I’ve checked the GPIO PA1..PA4 the voltage is according to the potentiometer position for each PAx - It’s not a harware/wiring issue.


I assume there is something with this GPDMA1 and may be it’s Linked list … I’m not familiar with these… I think tried everything I knew … I am supposed to just set ADC1 4 channels on a DMA … I’m so frustrated … It’s the 3rd day I’m fighting with this MCU ... 
 

Ozone
Principal
June 17, 2026

Not sure about your experience with MCUs in general or STM32s in particular.
But I usually recommend a gradual approach, i.e. verifying one part of a more complex system alone, and only then advance to the next element.
In this case, perhaps try without DMA first, enable the EOC and EOS interrupts of the ADC, and use those to sort out the values.
For 4 channels you would get 4 sequential EOC interrupts for each channel, and an EOS interrupt that the seuence is finished. This EOS interrupt comes probably concurrent with the last EOC interrupt, so your handler code should be prepared for that.

The H7 ADCs probably require an initial calibration, you can check at this accasion as well.

As mentioned, I don’t use Cube/Hal generated code, so I can only give more generic hints regarding DMA usage (assuming  the ADC DMA relation is similiar to the F4 devices).
Here a code xample for the F3. It is based upon SPL code, but you should recognize terms and DMA register values :
 

I suppose you get the picture - transfer size must be correct (HalfWord for 12-bit), peripheral increment disabled and memory increment enabled. Circular mode enabled means it repeats until you stop the timer/ADC.
Buffer size is the total number of items per transfer, in the configured data size (Halfword here), not bytes.

I use to have a multiple data sets transferred back to back (80 in this case), and get notified by the TC interrupt when the buffer is full.

Your HAL code should do basically the same, I recommend to check it.

CSand
CSandAuthor
Senior
June 17, 2026

Let me share my config … 
 


 

 

 

 

 

 

CSand
CSandAuthorBest answer
Senior
June 17, 2026

 

Well it just went into my mind that I should move the potentiometer that is read correctly to a different channel - and the good reading moved on that channel … 🤣

It looks that the issue was actually a bad GND connection on the connector used to supply all the other pot’s. The pot that was working has independent/different supply circuit…  
I suspect wen I used the multimeter I made a stronger GND connection with the probe - so I measured good values! But when I tucked the probe away ...

 

Yet it is another lesson to trust myself much more !!

Thanks for support!