cancel
Showing results for 
Search instead for 
Did you mean: 

COMP2 and EXTI does not seem to work using HAL (STM32L452)

MTadr.1
Associate II

Using COMP2 with internal voltage reference

When using COMP with interrupt as soon as I call HAL_COMP_START(&hcomp2); and interrupt is triggered even if COMP input GPIO is grounded.

If i let the code run a trigger is never regenerated afterwards. I have a feeling something is wrong with HAL_COMP_Init or HAL_COMP_Start

3 REPLIES 3

How is COMP2 input connected?

Read out and check/post COMP2, EXTI and relevant GPIO registers content.

How do you clear the EXTI flag? Did you verify that that code works?

JW

MTadr.1
Associate II

Here is EXTI registers before and after COMP2, by the way the COMP_INP pin is grounded no interrupt should be triggered

Pending register 1 (EXTI_PR1)

0693W00000KaIbvQAF.pngPending register 1 (EXTI_PR1)0693W00000KaIbqQAF.pngCOMP2_CSR

0693W00000KaIefQAF.png 

Okay so COMP2_CSR is 0x40830131, which means EN=1, INMSEL=0b011=VREFINT(*), INPSEL=0b10=PA3 (is that the pin you are using?), hysteresis is set to high, SCALEN is set which is expected for using VREFINT. Also POLARITY is zero (i.e. no inversion).

So, you say that the pin set to + input of comparator (PA3?) is grounded, -input of comparator is at VREFINT i.e. cca 1.2V.

Yet output (VALUE bit) is one.

Even if PA3 would not be configured as Analog in its respective GPIO_MODER, I wouldn't expect it to be internally tied to voltage higher than VREFINT.

Now to (*) above - reading the COMP chapter in RM I noticed this:

0693W00000KaeuQQAR.pngWhile I believe this is an error and the footnote refers to DAC_CH2 - which indeed should not be present in 'L44x and 'L45x - this is genuinely confusing.

I don't have an 'L45x at hand to try, but I'd recommend you to review the relevant GPIO setting, and to try find a combination of INMSEL/INPSEL which reliably reflects changes in input pin voltage onto the VALUE bit. You may perhaps want to experiment on a "known good" board e.g. Nucleo or Disco, and you may perhaps also observe the comparator output by setting the appropriate pin.

The EXTI interrupt is then just consequence of what happens in the comparator.

JW