cancel
Showing results for 
Search instead for 
Did you mean: 

How to read ADC without DMA ?????

sgordon777
Associate III

Board: NUcleo 64-G474

 

 

I just want to read 2 channels of an ADC but am presented with a bewildering array of incredibly confusing options: Ranks, Continuous mode, discontinous mode, number of conversions, oversampling, triggers, etc, etc, etc. The embedded "help" is completely useless.

I have two SE channels of ADC1 enabled (1 and 2), and I want to sample them both NOT in DMA. Seems reaonsonable but after hours of trying I can find nothing that works, and no resources to help. I'm trying the code below and various offshoots of it.

 

  while (1)
  {
 
  HAL_ADC_Start(&hadc1); // start the adc
  HAL_ADC_PollForConversion(&hadc1, 1000); // poll for conversion
  adc1_val = HAL_ADC_GetValue(&hadc1); // get the adc value
 
  HAL_ADC_Start(&hadc1); // start the adc
  HAL_ADC_PollForConversion(&hadc1, 1000); // poll for conversion
  adc2_val = HAL_ADC_GetValue(&hadc1); // get the adc value
  HAL_ADC_Stop(&hadc1); // stop adc
 
   printf("adc=[%d, %d]\n\r", adc1_val, adc2_val);

 

 

 

sgordon777_0-1710460374786.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
RomainR.
ST Employee

Hi @sgordon777 

Here in attached my example to use ADC1 Channel1 & Channel2 without DMA (PA0 & PA1)

You can test it on your side (STM32CubeIDE and Nucleo-G474RE)

If you need to build the project, ask OK to build without invoking Device Configuration Tool code generation by CubeMX.

RomainR_0-1710518007346.png

The reason is because the initial Mx configuration has been overwritten in the code.

I hope it will help you?

Thank you to give your feedback.
Best regards,

Romain

 

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.

View solution in original post

5 REPLIES 5
RomainR.
ST Employee

Hi @sgordon777 

Here in attached my example to use ADC1 Channel1 & Channel2 without DMA (PA0 & PA1)

You can test it on your side (STM32CubeIDE and Nucleo-G474RE)

If you need to build the project, ask OK to build without invoking Device Configuration Tool code generation by CubeMX.

RomainR_0-1710518007346.png

The reason is because the initial Mx configuration has been overwritten in the code.

I hope it will help you?

Thank you to give your feedback.
Best regards,

Romain

 

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.

Thanks

 

Hi @sgordon777 

Does this help you? Any feedback?

BR

Romain,

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.

Please, any example for STM32C0 family? This device has no ADC independent mode available and I need to run ADC without DMA for 0,1,5 and 6 channels.

Thanks in advance,
Gaston

Hello @Gaston 

The ADC of the STM32C0 is independent by default since this product has only one ADC instance.
This independent or dual mode configuration is only applicable in the case where you have several ADC instances like the STM32G4 which can have 5 ADCs.

For your question, you can refer to the STM32G4 project that I posted.
You can then create a CubeMX project, configure your 4 channels, activate the Scan mode and a sequence of 4 conversions with an adapted ADC sampling time.
Once your project is generated, you manually change in the MX_ADC_Init() configuration the field:
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
Then you comment out all the lines that are related to the sconfig configuration (refer to my STM32G4 project)
Finally, you write the same function below:
static uint32_t ADC_Select_Channel(uint32_t channel) that you can call in your application.

What is the reason that forces you not to use ADC scan mode with DMA which makes things much easier since all STM32s are designed to work like this?

Best regards,

Romain,

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.