Skip to main content
Visitor II
October 27, 2024
Solved

STM32G474 Unable to initialize more than one ADC

  • October 27, 2024
  • 1 reply
  • 992 views

Hi All,

I'm trying to setup 2 ADCs in continous mode but I'm failing miserably. 

In CubeMX I set the first ADC in continuous mode, triggered by software, then HAL_ADC_Start_IT(&hadc1); and it works as expected (I have a callback to read the value).

Then, I go to the second ADC, setup the samme manner as the first one, but it does not work, only the first interrupt is triggered.

 HAL_ADC_Start_IT(&hadc1); //only this Interrupt works
 HAL_ADC_Start_IT(&hadc2);

If I change the order of the calls (hadc2 first) the first one called works and the second is never triggered.

Is there any special caveat to activate both ADCs? I'm starting to consider the possibility of this board uses a bad clone.

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

    Pedro, 

    I found the issue: I was using a ADC_CLOCK_ASYNC_DIV1 prescaler and the first interrupt was eating all the CPU cycles. Once I switched to ADC_CLOCK_ASYNC_DIV8 (or any larger prescaler value) it was able to trigger the second interrupt.

    Thanks for your time

    1 reply

    Graduate II
    October 28, 2024

    Hi,

    I'm not familiar with the STM32G4, however, I am aware that the ADC1 & ADC2 are "tightly coupled" in that device - you may not be able to have separate CallBacks (I assume you are using CallBacks).

    I've also noted that ADC1 & ADC2 share the same interrupt vector. You may need to differentiate between them in the CallBack function...

    I hope that helps.

    Kind regards
    Pedro

    aldoirAuthorAnswer
    Visitor II
    October 28, 2024

    Pedro, 

    I found the issue: I was using a ADC_CLOCK_ASYNC_DIV1 prescaler and the first interrupt was eating all the CPU cycles. Once I switched to ADC_CLOCK_ASYNC_DIV8 (or any larger prescaler value) it was able to trigger the second interrupt.

    Thanks for your time