#13 ADC conversion doesn't start automatically


ADC conversion doesn't start automatically. Problem in os/hal/platforms/STM32/adc_lld.c file. For start you must write ADC_CR2_ADON bit in ADC1->CR2 ones more.

STM32 manual says:
"Conversion starts when ADON bit is set for a second time by software after ADC power-up time"

I have create and attach the patch. But may be I misunderstood something (I'm newbie)


  • barthess

    barthess - 2010-12-07


  • Giovanni Di Sirio

    • assigned_to: nobody --> gdisirio
    • status: open --> open-postponed
  • Giovanni Di Sirio


    The line

    /* ADC start.*/
    adcp->ad_adc->CR2 |= ADC_CR2_SWSTART | ADC_CR2_EXTTRIG;

    does write ADC_CR2_ADON a 2nd time even if the bit is not shown explicitly, the ADON bit is read from the CR2 register and then rewritten,

    Are you experiencing some specific problem with the driver?

  • barthess

    barthess - 2010-12-08

    main.c for ARMCM3-STM32F103-GCC demo that reproduce the bug

  • barthess

    barthess - 2010-12-08


    Yes, I have problems with the driver.

    ADC works only with my patch or if I manually set ADC_CR2_ADON bit after the adcStartConversion() function. I have attached file that reproduce the bug.

  • Giovanni Di Sirio

    I see.

    The only difference I found with the ADC test demo is in the initialization structure. The demo also specifies ADC_CR2_EXTSEL_SWSTART into the CR2 configuration field, see the file ./testhal/STM32/ADC/main.c. The flag is required for software-triggered conversions.

    Can you verify if adding that flag fixes your problem?

    The current implementation implicitly uses the EXTTRIG flag that also requires that ADC_CR2_EXTSEL_SWSTART.

    Probably would be a good idea to not enforce EXTTRIG and leave that to the configuration structure. The start code would be similar to your patch. I'll have to make some tests and think about this.

  • Giovanni Di Sirio

    In the meanwhile I move the ticket in accepted state.

  • Giovanni Di Sirio

    • status: open-postponed --> open-accepted
  • barthess

    barthess - 2010-12-08

    Yes, adding this flag fixes my problem.

    I haven't find the ADC demo and have write code from scratch. This was my fault.

  • Giovanni Di Sirio

    • priority: 5 --> 3
  • Giovanni Di Sirio

    I committed a change in the repository, starting from 2.1.6 ADC_CR2_EXTSEL_SWSTART in the configuration will no more be required.
    It is a bit different from your patch because I also made another change and an optimization in the code.

  • Nobody/Anonymous

    I have tested new version on my stm32 board. Works fine, as expected.

  • Giovanni Di Sirio

    Moving into Feature Requests.

  • Giovanni Di Sirio

    • milestone: 953057 -->
    • labels: 1267296 -->
  • Giovanni Di Sirio

    • status: open-accepted --> closed
  • Giovanni Di Sirio



Log in to post a comment.