2021-05-23 05:31 PM
2021-05-28 08:46 AM
Hello @kiwironnie ,
according to the RM it should work from both LP modes.
Jarda
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2021-05-28 01:47 PM
Thanks, yes, I'm aware that the manual indicates the comparators should work in all stop modes. For me though they work in Sleep mode but do not wake up the mcu in any Stop mode. Hence the question. The code is the same in both cases other than changing the low power mode call. The device enters low power mode but isn't being woken up as it is in Sleep mode.
2021-05-31 06:32 AM
Please check the configuration of SCLAEN, BRGEN and selection of INMSEL. Is the EXTI configured correctly?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2021-05-31 03:53 PM
Thanks for getting back.
HAL is being used to setup the comparators as follows:
static void MX_COMP1_Init(void)
{
hcomp1.Instance = COMP1;
hcomp1.Init.InvertingInput = COMP_INPUT_MINUS_1_4VREFINT;
hcomp1.Init.NonInvertingInput = COMP_INPUT_PLUS_IO3; // PA1
hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp1.Init.Hysteresis = COMP_HYSTERESIS_HIGH;
hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
hcomp1.Init.Mode = COMP_POWERMODE_MEDIUMSPEED;
hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING;
if (HAL_COMP_Init(&hcomp1) != HAL_OK)
{
Error_Handler();
}
}
static void MX_COMP2_Init(void)
{
hcomp2.Instance = COMP2;
hcomp2.Init.InvertingInput = COMP_INPUT_MINUS_1_4VREFINT;
hcomp2.Init.NonInvertingInput = COMP_INPUT_PLUS_IO1; // PB4
hcomp2.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp2.Init.Hysteresis = COMP_HYSTERESIS_HIGH;
hcomp2.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
hcomp1.Init.Mode = COMP_POWERMODE_MEDIUMSPEED;
hcomp2.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
hcomp2.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING;
if (HAL_COMP_Init(&hcomp2) != HAL_OK)
{
Error_Handler();
}
}
Interrupts:
/* COMP interrupt Init */
HAL_NVIC_SetPriority(COMP_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(COMP_IRQn);
As said, this is working in Sleep mode. When the voltage crosses 1/4 VREFint an interrupt is generated that wakes the mcu. Exactly the same configuration is being used with Stop mode, just the call to Stop rather than Sleep changed, but it isn't coming out of Stop mode. Stop mode wake-up is working elsewhere, with RTC events causing a wake-up, no problem.
That is:
COMP_Start(); // comparators are stopped when they trigger
// comparator interrupt causes wakeup
HAL_SuspendTick();
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
HAL_ResumeTick(); // on wake-up;
vs
COMP_Start(); // comparators are stopped when they trigger
HAL_SuspendTick();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
PWR_ExitStopMode( ); // which enables clocks, IO and resumes tick
Any other suggestions appreciated. Thanks. Ron