Skip to main content
ControlFreak
Associate III
September 14, 2018
Solved

STM32L4 -Analog WatchDog with Interrupt in HAL library

  • September 14, 2018
  • 4 replies
  • 1663 views

I am using STM32L432 with HAL library. I am programming ADC1 Channel 16 (i.e. PB1) as analog input signal. I have initialized ADC as Analog WatchDog-1 with Interrupt and without DMA, so that I dont have to continuously monitor my input voltage, if my input voltage goes out of certain threshold values, my AWD1 interrupt flag is set. Please find my initialization attached below.

Now my problem is as soon as I start my ADC using "HAL_ADC_Start_IT(&adcHandle);"(WHICH DOCUMENTATION SAY "ADC Conversion by Interruption"), my EOC-End of conversion flag,ESMP-End of Sampling Flag is also set (almost immediately--I am not concerned about this flags) and My ISR is executed. And Never leaves ISR (As at the start of ISR I stop my conversion in ADC channel and before returning to main program, I again start my ADC conversion using HAL_ADC_Start_IT(&adcHandle)) otherwise my analog watchdog does not take new value

How can I make my ADC to execute ISR only when AWD1 Interrupt Flag is set? (I guess this is bug in HAL library or I am missing something)

Please find screenshot of my debugger window after executing HAL_ADC_START_IT (DR is within limits)

Any Help will be highly appreciated

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

    Cube is open source so you can examine its functions yourself.

    HAL_ADC_Start_IT() is clearly not intended for "enable conversion with *watchdog* interrupt"; rather, it enables conversion with end-of-conversion interrupt. That's what you see to happen.

    So you need to enable the watchdog interrupt separately (there's some framework in Cube for that, resulting in calling HAL_ADC_LevelOutOfWindowCallback() from HAL_ADC_IRQHandler() when the WD is hit) and then enable the conversions in whatever means - if you are not interested in the conversion results, then maybe the best option is to enable continuous conversions mode and start the conversions "plainly" without DMA or interrupts.

    I don't Cube so won't help with the details. There are examples e.g. [STM32Cube_FW_L4_Vx.xx.x]\Projects\STM32L476G-EVAL\Examples\ADC\ADC_AnalogWatchdog\

    JW

    4 replies

    waclawek.jan
    waclawek.janBest answer
    Super User
    September 15, 2018

    Cube is open source so you can examine its functions yourself.

    HAL_ADC_Start_IT() is clearly not intended for "enable conversion with *watchdog* interrupt"; rather, it enables conversion with end-of-conversion interrupt. That's what you see to happen.

    So you need to enable the watchdog interrupt separately (there's some framework in Cube for that, resulting in calling HAL_ADC_LevelOutOfWindowCallback() from HAL_ADC_IRQHandler() when the WD is hit) and then enable the conversions in whatever means - if you are not interested in the conversion results, then maybe the best option is to enable continuous conversions mode and start the conversions "plainly" without DMA or interrupts.

    I don't Cube so won't help with the details. There are examples e.g. [STM32Cube_FW_L4_Vx.xx.x]\Projects\STM32L476G-EVAL\Examples\ADC\ADC_AnalogWatchdog\

    JW

    ControlFreak
    Associate III
    September 17, 2018

    As per example ([STM32Cube_FW_L4_Vx.xx.x]\Projects\STM32L476G-EVAL\Examples\ADC\ADC_AnalogWatchdog\), I used HAL_ADC_START() instead, and now my ADC_DR is not getting updated with new conversion data values

    ControlFreak
    Associate III
    September 17, 2018

    I have used the logic mention in my first comment on other ARM processor-STM32F405 with standard library and everything works fine and now with HAL library I am facing this issues.

    ControlFreak
    Associate III
    October 11, 2018

    I ended up using with DMA and Interrupt. Thanks JW for your support and time