cancel
Showing results for 
Search instead for 
Did you mean: 

Pwr_wakeup

SRAM.11
Associate III

I couldn't able wakeup the system after standby (wakeup should be switching ON mains ) the wakeup pin PA2 is connected to mains pin configured for pwr wakeup.

 

 

int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC1_Init();
  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */

  /* Enable Power Control clock */
    __HAL_RCC_PWR_CLK_ENABLE();
    /* Check if the system was resumed from Standby mode */
    if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
    {
      /* Clear Standby flag */
      __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
      /* Check and Clear the Wakeup flag */
      if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF4) != RESET)
      {
        __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF4);
      }
    }


  while(Mains<0.1)
    {
    	count++;
    	if(count>=30)
    	{
    		 HAL_PWR_EnterSTANDBYMode();

    	}
    	else
    	{
    		count=0;
    	}
    }
  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN4_HIGH);




  while (1)
  {
	  HAL_Delay(100);
	  	  //  MAINS INPUT
	  	  	  Adc_Mains();
	  	  	  HAL_ADC_Start(&hadc1);
	  	  	  HAL_ADC_PollForConversion(&hadc1,1000);
	  	  	  Mains=HAL_ADC_GetValue(&hadc1);
	  	  	  Mains=Mains*2/4095;
	  	  	  HAL_ADC_Stop(&hadc1);
	           HAL_Delay(100);

	       //Battery operation
	           Adc_Vbat();
	            HAL_ADC_Start(&hadc1);
	            HAL_ADC_PollForConversion(&hadc1,1000);
	            Vbat=HAL_ADC_GetValue(&hadc1);
	            Vbat=Vbat*2/4095;
	            HAL_ADC_Stop(&hadc1);
	            HAL_Delay(100);

	       //OPEN CIRCUIT DETECT
	        Adc_OCD();
	  	  	HAL_ADC_Start(&hadc1);
	  	    HAL_ADC_PollForConversion(&hadc1,1000);
	  	    OCD=HAL_ADC_GetValue(&hadc1);
	  	    OCD=OCD*2/4095;
	  	    HAL_ADC_Stop(&hadc1);
	  	    HAL_Delay(100);
	  	  //BATTERY TEMPARATURE
	  	    		Adc_Temp();
	  	  	  	  	HAL_ADC_Start(&hadc1);
	  	  	  	    HAL_ADC_PollForConversion(&hadc1,1000);
	  	  	  	    Temp=HAL_ADC_GetValue(&hadc1);
	  	  	  	    Temp=Temp*2/4095;
	  	  	  	    HAL_ADC_Stop(&hadc1);
	  	  	  	    HAL_Delay(100);

	  	  	  	// Check mains and mains fail

	  	  	  	if(Mains>0.1)


	  	  	  	{
	  	  	  		   if((Mains<1) &&(Vbat>0.9))
	  	  	  		   	   {
	  	  	  			   	   En_Emergency(1);
	  	  	  			   	Set_LED(0);

	  	  	  		   	   }

	  	  	  		   else
	  	  	  		   	   {
	  	  	  			   En_Emergency(0);
	  	  	  		   	   }

	  	  	  	}
	  	  	//   MAINS ON
	  	  	if(Mains>1.2)
	  	  	{
	  	  		if(Vbat>1.5 || Vbat<0.5)     //OPEN CIRCUIT OR ZERO BATT LEVEL
	  	  				{
	  	  				Set_LED(0);
	  	  				Batt_Chrge(1);
	  	  				}
	  	  		else if(Vbat <0.94 )     // START CHARGING LEVEL
	  	  				{
	  	  				Set_LED(1);
	  	  				Batt_Chrge(1);
	  	  				}
	  	  		else if(Vbat >0.98 )   // STOP CHARGING LEVEL
	  	  				{
	  	  				Set_LED(1);
	  	  				Batt_Chrge(0);

	  	  				}
	  	  		//BATTERY TEMPARATURE CHECK

	  	  	 if(Temp<0.17  || Temp>0.83)
	  	  	 {
	  	  		Batt_Chrge(0);
	  	  		Triple_Flash();
	  	  	 }
	  	  	 else if((Temp>0.17  || Temp<0.83))
	  	  	 {
	  	  		Batt_Chrge(1);

	  	  	 }
	  	  	}

 

 

2 REPLIES 2
TDK
Guru

If Mains is initialized to 0, which as a global variable presumably it is, your code will never get out of this loop and thus will never enter the main loop.

 

 

  while(Mains<0.1)
    {
    	count++;
    	if(count>=30)
    	{
    		 HAL_PWR_EnterSTANDBYMode();

    	}
    	else
    	{
    		count=0;
    	}
    }

 

 

 

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

can you please help me to solve.

if(Mains<1)
{
count++;
if(count>=300);
{
HAL_PWREx_EnterSHUTDOWNMode();
}
}

i tried this too but the problem is in wakeup