Skip to main content
Visitor II
March 14, 2024
Solved

How to read ADC without DMA ?????

  • March 14, 2024
  • 1 reply
  • 4872 views

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

 

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

    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

     

    1 reply

    RomainR.Answer
    ST Employee
    March 15, 2024

    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

     

    Visitor II
    March 15, 2024

    Thanks

     

    ST Employee
    March 16, 2024

    Hi @sgordon777 

    Does this help you? Any feedback?

    BR

    Romain,