2022-02-22 10:49 PM
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
2022-02-23 12:03 AM
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
2022-02-23 10:56 AM
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)
Pending register 1 (EXTI_PR1)COMP2_CSR
2022-02-26 06:29 AM
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:
While 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