Skip to main content
Explorer
August 10, 2025
Solved

STM32 ADC not working?

  • August 10, 2025
  • 1 reply
  • 682 views

Ive been trying to get active passthrough between my adc and dac from pa1 and pa0 respectively. Ive confirmed all my functions are being called but i just cant seem to get any value loaded into my DAC. if i give it a value manually, i get the correct value at the pin. I am putting a 2.6 VDC source at my adc pin but have failed to get anything out. I have included my main.c file. I am using the nucleo-l476rg board

    This topic has been closed for replies.
    Best answer by waclawek.jan

    > failed to get anything out

    This is not a proper problem description. You should describe in detail, what are the observations and how do they differ from the expectations.

    You have to disable ADC deep powerdown and enable its regulator first.

    Also, calibration is recommended. Read the ADC chapter in RM.

    /*
     To start ADC operations, it is first needed to exit Deep-power-down mode by setting bit DEEPPWD=0.
    
    Then, it is mandatory to enable the ADC internal voltage regulator by setting the bit
    ADVREGEN=1 into ADCx_CR register. The software must wait for the startup time of the
    ADC voltage regulator (T ADCVREG_STUP ) before launching a calibration or enabling the
    ADC. This delay must be implemented by software
    */
    
     ADC1->CR = 0
     | (0 * ADC_CR_DEEPPWD)
     | (1 * ADC_CR_ADVREGEN)
     ;
    
     LoopDelay(100); // t ADCVREG_STUP = 20us max -- this is uncalibrated delay, but it's certainly more than 1 cycle per loop, so at 4MHz this is at least 100/4=25us (use any other delay you have at hand)
    
    
     // we are not going to be measuring differentially so don't need to set ADCALDIF prior to launching calibration
     ADC1->CR = 0
     | (1 * ADC_CR_ADVREGEN)
     | (1 * ADC_CR_ADCAL)
     ;
    
     while (ADC1->CR & ADC_CR_ADCAL); // wait until calibration ends
     // and that's it

    JW

    1 reply

    Super User
    August 10, 2025

    > failed to get anything out

    This is not a proper problem description. You should describe in detail, what are the observations and how do they differ from the expectations.

    You have to disable ADC deep powerdown and enable its regulator first.

    Also, calibration is recommended. Read the ADC chapter in RM.

    /*
     To start ADC operations, it is first needed to exit Deep-power-down mode by setting bit DEEPPWD=0.
    
    Then, it is mandatory to enable the ADC internal voltage regulator by setting the bit
    ADVREGEN=1 into ADCx_CR register. The software must wait for the startup time of the
    ADC voltage regulator (T ADCVREG_STUP ) before launching a calibration or enabling the
    ADC. This delay must be implemented by software
    */
    
     ADC1->CR = 0
     | (0 * ADC_CR_DEEPPWD)
     | (1 * ADC_CR_ADVREGEN)
     ;
    
     LoopDelay(100); // t ADCVREG_STUP = 20us max -- this is uncalibrated delay, but it's certainly more than 1 cycle per loop, so at 4MHz this is at least 100/4=25us (use any other delay you have at hand)
    
    
     // we are not going to be measuring differentially so don't need to set ADCALDIF prior to launching calibration
     ADC1->CR = 0
     | (1 * ADC_CR_ADVREGEN)
     | (1 * ADC_CR_ADCAL)
     ;
    
     while (ADC1->CR & ADC_CR_ADCAL); // wait until calibration ends
     // and that's it

    JW