cancel
Showing results for 
Search instead for 
Did you mean: 

Cant get STM32L011x Sleep mode with timer 2 interrupt every 70us.

Sid
Associate II

Hello Every1,

Warning! I am a total noob in STM32 coding. following is my objective:

I already have a code up and running(without the sleep) that reads the ADC value every 70us. Now i want the microcontroller to sleep every 70us while its waiting for the interrupt from the Timer2. I am not showing the Interrupt Routine as it works for the Tim2 interrupt. Given below is a snippet from my main code where i am trying to config the sleep mode.

int main(void)
{
  /* MCU Configuration----------------------------------------------------------*/
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_ADC_Init();
  MX_LPUART1_UART_Init();
  MX_TIM2_Init();
  /* USER CODE BEGIN 2 */
 
  for(int j=0;j<=2;j++)
      {
        HAL_GPIO_TogglePin(GPIOB, LED_Red_Pin); // LED Red
        HAL_Delay(500); // 500Ms delay
      }
 
    HAL_ADC_Start(&hadc);  // start ADC
 
     HAL_TIM_Base_Start_IT(&htim2);  // timer set for 70us
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    HAL_SuspendTick();
 
    /* Enter Sleep Mode , wake up is done once jumper is put between PA.12 (Arduino D2) and GND */
    HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
 
    /* Resume Tick interrupt if disabled prior to SLEEP mode entry */
    HAL_ResumeTick();
	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  /* USER CODE END WHILE */
 
  /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
 
}

The problem is i cant put my microcontroller into sleep and I am sure i am not configuring something properly. I generated the base code and configuration using STMCubeMX.

Any help in this regard is very much appreciated.

P.S I am using IAR.

Regards

Sid

0 REPLIES 0