cancel
Showing results for 
Search instead for 
Did you mean: 

PVD (Programmable Voltage Detector) interrupt not working

HBavi.1
Associate III

Hello,

I am using NUCLEO-STM32G071RB hardware. I configure to detect PVD (falling edge) but it looks like it doesn't detect any interrupt.

/**
  * @brief  Configures the PVD resources.
  * @param  None
  * @retval None
  */
void PVD_Config(void)
{
  /*##-1- Enable Power Clock #################################################*/
  /* Enable Power Clock */
  __HAL_RCC_PWR_CLK_ENABLE();
  
  /*##-2- Configure the NVIC for PVD #########################################*/
  HAL_NVIC_SetPriority(PVD_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(PVD_IRQn);
 
  /* Configure the PVD Level to 3 and generate an interrupt on rising and falling
     edges(PVD detection level set to 2.5V, refer to the electrical characteristics
     of you device datasheet for more details) */
  sConfigPVD.PVDLevel = PWR_PVDLEVEL_3;
  sConfigPVD.Mode = PWR_PVD_MODE_IT_RISING_FALLING;
  HAL_PWR_ConfigPVD(&sConfigPVD);
 
  /* Enable the PVD Output */
  HAL_PWR_EnablePVD();
}
 
/**
  * @brief  PWR PVD interrupt falling callback
  * @param  none 
  * @retval none
  */
void HAL_PWREx_PVD_Falling_Callback(void)
{
  /* Turn On LED4 as voltage is above threshold */
  BSP_LED_On(LED4);
 
  /* Set uwToggleOn global variable to one to disable toggle */
  uwToggleOn = 1u;
}

3 REPLIES 3
TDK
Guru

Looks like you're just trying to run an existing example:

https://github.com/STMicroelectronics/STM32CubeG0/blob/c6cb8664ae0542c33f81046d735ee9492d5df0f3/Projects/STM32G081B-EVAL/Examples/PWR/PWR_PVD/Src/main.c

Can you show the voltage is going below 2.5V via a scope plot?

Is your code still running and otherwise behaving correctly after voltage drops below 2.5V?

If you feel a post has answered your question, please click "Accept as Solution".
HBavi.1
Associate III

Thank you for your quick response. As I told you that, I am using NUCLEO-STM32G071RB hardware and it's powered using USB Port.

I need to save current value of RTC registers in the flash memory if power-off is detected (Internally) and read it back when power is restored. I am able to read and write data into flash memory independently but somehow PVD detection is not happening and because of which data is not saved in to flash memory during power-off.

As you rightly mentioned in the comment above, I tried to use sample program provided by STM Studio but somehow its not detecting power failure. Any clue? Am I missing something?

TDK
Guru

That didn't answer either question I asked. I'm interested in how you're creating the <2.5V condition. If you just cut power, the MCU will go from 2.5V to 1.8V (or whatever BOR is set at) and below quickly enough that your program won't be able to do much, if anything. It takes time to write to flash and you need to ensure there is sufficient time between when the voltage drops below 2.5V and when the MCU loses all power. Requirements like wait states will also be affected by VDD being lowered and you'll need to ensure the clock settings are still valid for the new voltage range.

If you feel a post has answered your question, please click "Accept as Solution".