2023-08-01 06:13 AM
I needed a help how to implement shutdown mode and wakeup from external reset in my application
while (1)
{
HAL_Delay(100);
// MAINS INPUT
Adc_Mains();
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,1000);
Mains=HAL_ADC_GetValue(&hadc1);
Hands=Hands*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);
}
}
if(Mains<1)
{
// OCD=HAL_ADC_GetValue(&hadc1);
if(OCD>0.3||OCD<0.6)
{
Set_LED(0);
}
else if(OCD<0.3 || OCD>0.6)
{
Double_Flash();
}
}
// MAINS ON
if(Mains>1.2)
{
if(Vbat>1.5 || Vbat<0.5) //OPEN CIRCUIT OR ZERO BATT LEVEL
{
Set_LED(0);
Batt_Charge(1);
}
else if(Vbat <0.94 ) // START CHARGING LEVEL
{
Set_LED(1);
Batt_Charge(1);
}
else if(Vbat >0.98 ) // STOP CHARGING LEVEL
{
Set_LED(1);
Batt_Charge(0);
}
//BATTERY TEMPARATURE CHECK
if(Temp<0.17 || Temp>0.83)
{
Batt_Charge(0);
Triple_Flash();
}
else if((Temp>0.17 || Temp<0.83))
{
Batt_Charge(1);
}
}
.if my mains is off for 30 seconds it should be in shutdown mode.I have a option using wakeup4 pin but my config is not working.Can anyone pls give an idea for the implementation
Solved! Go to Solution.
2023-08-01 06:48 AM - edited 2023-08-01 06:49 AM
Hello @meena,
Configure wkup4 pin as EXTI and connect it to an external interrupt source (ex: button or sensor)
after enabling the wakeup, test if mains off (exp: mains<0.1)
if (Mains < 0.1) {
HAL_Delay(30000); // Wait for 30 seconds
if (Mains < 0.1) {
// Mains is still off, enter shutdown mode
HAL_PWR_EnterShutdownMode();
}
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.
2023-08-01 06:48 AM - edited 2023-08-01 06:49 AM
Hello @meena,
Configure wkup4 pin as EXTI and connect it to an external interrupt source (ex: button or sensor)
after enabling the wakeup, test if mains off (exp: mains<0.1)
if (Mains < 0.1) {
HAL_Delay(30000); // Wait for 30 seconds
if (Mains < 0.1) {
// Mains is still off, enter shutdown mode
HAL_PWR_EnterShutdownMode();
}
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.
2023-08-01 06:51 AM - edited 2023-08-01 07:37 AM
hi thanks for the reply I have this but this is entirely making my module shutdown its not waiting for 30 seconds
2023-08-01 07:06 AM
hi this worked thank you so much
if (Mains < 0.1) {
HAL_Delay(30000); // Wait for 30 seconds
if (Mains < 0.1) {
// Mains is still off, enter shutdown mode
HAL_PWREx_EnterSHUTDOWNMode();
}
2023-08-01 08:26 AM
Hello @meena,
yes right the HAL_Delay() will block your code, instead, the best approach is to use a timer that interrupts every 1s for example, in its callback, you read the value of mains for a period of 30s, once it reaches 30s, you set a flag, in while(1) loop you test on that flag and enter shutdown accordingly
Is that somehow clear?
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.
2023-08-03 03:03 AM
hi I am trying to code it in a way ,but standby mode is working its not waking up as in my previous post but I have to the below one now its not going to standby mode .I couldnt find whats wrong
__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);
}
}
//HAL_Delay(5000);
count++;
if(count>=30)
{
HAL_PWR_EnterSTANDBYMode();
}
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN4_HIGH);
2023-08-04 04:30 AM
if(Temp<0.17 || Temp>0.83)
{
Batt_Charge(0);
Triple_Flash();
}
else if((Temp>0.17 || Temp<0.83))
{
Batt_Charge(1);
}
2023-08-07 07:06 AM
thank you,Could you have any solution for exiting low power modes using wakeup pins
2023-08-07 09:45 AM