cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure ADC after wake up from STOP (low power mode)

manto.1
Senior

I am using LPTIM for periodic ADC reading (every ~250ms) and periodic IWDG refresh. CPU should go to Stop mode when the ADC value is under certain value. If the ADC value is over certain value then CPU should reset end continue in Run mode. ADC is clocked from HSE.

The problem is when in Stop mode IWDG doesnt get refreshed.

this is LTPIM callback

void HAL_LPTIM_AutoReloadMatchCallback(LPTIM_HandleTypeDef *hlptim){
	  if(systemData.inSleepMode){
		  // start HSE and PLL if in sleep mode
		  SYSCLKConfig_afterSTOP();
	  }
	  HAL_ADC_Start(&hadc1);
	  HAL_ADC_PollForConversion(&hadc1, 10);
	  systemData.gd3.batteryADC = HAL_ADC_GetValue(&hadc1);
 
	  HAL_IWDG_Refresh(&hiwdg1);
}

entry to the low power mode is in the IDLE_hook:

void vApplicationIdleHook( void )
{
 
	if(systemData.gd3.goToSleep){
		HAL_LTDC_DeInit(&hltdc);
		HAL_DMA2D_DeInit(&hdma2d);
		BSP_I2C2_DeInit();
 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
 
		HAL_PWREx_EnableFlashPowerDown();
 
		HAL_PWREx_ControlStopModeVoltageScaling(PWR_REGULATOR_SVOS_SCALE5);
		HAL_SuspendTick();
		HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_SLEEPENTRY_WFE);
//		//HAL_ResumeTick();
 
		//SYSCLKConfig_afterSTOP();
 
	}
 
	if((systemData.gd3.batteryADC < 400) && !systemData.gd3.goToSleep){
		systemData.gd3.goToSleep = true;
		HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_2);
		HAL_GPIO_WritePin(NET_S_ON_GPIO_Port, NET_S_ON_Pin, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(CAN_EN_GPIO_Port, CAN_EN_Pin, GPIO_PIN_RESET);
		HAL_GPIO_WritePin(LCD_EN_GPIO_Port, LCD_EN_Pin, GPIO_PIN_SET);
 
	}
	if(systemData.gd3.batteryADC > 900 && systemData.gd3.goToSleep){
		HAL_NVIC_SystemReset();
	}
	vTaskSetApplicationTaskTag(NULL, IdleTaskHook);
}

3 REPLIES 3
MM..1
Chief II

Why dont set to false ?

systemData.gd3.goToSleep

Tried like this now :

	if(systemData.gd3.batteryADC > 900 && systemData.gd3.goToSleep){
		systemData.gd3.goToSleep = false;
		HAL_NVIC_SystemReset();
	}

The first time I go to sleep I can wake up, the second time I go to sleep I can't wake up. Also I see on the ampere meter that the first time the power consumption is ~11mA and the second time it is 8mA.

Also IWDG timer is refreshed now, so the problem is probably in ADC configuration after wake up.

Check your system in STOP modes without debuger. If you enable debug in low power modes MCU do other way as real. Use leds or other way...

And SystemReset i mean reset all variables , then set any before call is waste of ...