Skip to main content
Graduate II
August 4, 2024
Question

Does HAL have constants for the total number of ADC channels?

  • August 4, 2024
  • 1 reply
  • 1367 views

Folks,

Does HAL have constants for the total number of ADC channels? 

I want to iterate through all channels and make sure that all of them are disabled.  Here's the code I have in mind. 

 

 ADC_ChannelConfTypeDef sConfig = {0};
 sConfig.Rank = ADC_RANK_NONE; // disable all channels

 const uint8_t nChannels = 19; // Does HAL already have a constant for the number of ADC channels?
 for (uint32_t iChannel = 0; iChannel < nChannels; ++iChannel)
 {
 sConfig.Channel = iChannel;
 if (HAL_ADC_ConfigChannel(hadc, &sConfig) != HAL_OK) Error_Handler();
 }

 

I'm declaring my own constant nChannels = 19 .  The number 19 came from the STM32G4 family reference manual.  I wonder if HAL already has a constant for that.

Best regards,
- Nick

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    August 4, 2024

    Hello @Nick Alexeev 

    according to what I know, there is not such a definition since the HAL driver is implemented for different MCU of the same family (G4 for your case). The number of channels and the repartition of channels may change from an MCU to another.

    Best Regards.

    STTwo-32 

    Graduate II
    August 4, 2024

    I've got another question related to reconfiguring the ADC channels at runtime.  How can I disable channels which aren't used at the given time?

    In one part of my program ADC2 is reading channels 1,2,4 in scan mode with DMA.  In another part of the program ADC2 is reading channel 9.

    I saw code examples which used ADC_RANK_NONE to disable channels [if I understood it correctly].  But the HAL for my microcontroller (STM32G4) doesn't define ADC_RANK_NONE .

    Technical Moderator
    August 4, 2024

    This is a new question. So, suggest you to select a best answer for your original request if it is answered and create a new thread for this question with more details. Doing that will give you the chance to have more visibility from our forum members and maybe have more ideas. It will also help others who have the same request.

    Best Regards.

    STTwo-32