cancel
Showing results for 
Search instead for 
Did you mean: 

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

Nick Alexeev
Associate III

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

6 REPLIES 6
STTwo-32
ST Employee

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 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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 .

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 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

This information should be available in the documents and examples.  I shouldn't have to ask this in a forum.

So I don't see an answer worth accepting here.

If have to start another thread, I might as well do it on a different forum.

Hello @Nick Alexeev 

This is something that you can do for sure. You just have to stop the current conversion, reconfigure the ADC and restart the conversions with the new settings. That is how you can do it. 

Ps: The original question is your first question (about the number of channels). So, i've asked you to select the best answer for this request to give it more visibility (if someone else have a simular question). Also, i've told you that it will be better for the new question (about changing adc channels) to be in a new post, so other users that have a simular request may fond it easy.

We are here to help.

Best Regards.

STTwo-32 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.


So, i've asked you to select the best answer for this request to give it more visibility (if someone else have a simular question).

So I'm not going to accept an answer if it's not that good of an answer.  It doesn't require better visibility.