AnsweredAssumed Answered

STM32L0 Stop Mode Not Working Properly

Question asked by eren eraslan on Sep 23, 2017

Hello,

 

Currently, I am working on optimizing current consumption by using STOP Mode of the STM32L053C6T6 processor.

I'm facing a problem that I can not get through, and I'm very happy if you can help.

First of all, I would like to explain the algorithm in a very simplified way.

In the while loop, I print to Pc "STARTED" through the UART-Serial converter. Next, I set the RTC alarm to 10 seconds later. And the finally I sleep the MCU by using  STOP MODE. After 10 seconds, MCU wakes up properly. So far everything is normal. After MCU wake up, I call the System Clock Config function. I print "woken-up" on the PC screen through UART. I can work this way forever But I do not like the current that circuit consume.

 

To reduce the power consumption, I set all the pins to analog before entering sleep mode. this method worked very well on reducing current consumption. But after all the pins are analog and MCU goes sleep and wake up, the MCU can not send to string to PC. I think UART Module does not work properly...

But I/O's and systick timer are running. I can understand this by toggling the LED in a certain delay(with HAL_DELAY)

Here is my codes 

 

int main(void)
{
     HAL_Init();
     SystemClock_Config();

     MX_GPIO_Init();
     MX_ADC_Init();
     MX_I2C1_Init();
     MX_RTC_Init();
     MX_TIM22_Init();
     MX_USART1_UART_Init();
     MX_USART2_UART_Init();
     Init_RTC();
     HAL_Delay(500);
     while(1)
     {
          printf("Started\n\r");                              
          for(uint16_t count1 = 0;count1<25;count1++){
               HAL_GPIO_TogglePin(STATE_LED0_GPIO_Port,STATE_LED0_Pin);
               HAL_Delay(25);
          }
          SetAlarm(10);                                   //10sn sonra alarm kuruyor
          EnterStopMode();                              //Uyku modu ayarlamalari
          printf("Woken-Up\n\r");
          HAL_Delay(1000);      
     }
}


void EnterStopMode(void)
{
  GPIO_InitTypeDef GPIO_InitStruct;
  //A ve B portlarini kullandigim icin bu portlari analog yaptim
  __HAL_RCC_GPIOA_CLK_ENABLE();                          
  __HAL_RCC_GPIOB_CLK_ENABLE();

  /* Configure all GPIO port pins in Analog Input mode (floating input trigger OFF) */
  GPIO_InitStruct.Pin = GPIO_PIN_All;
  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = GPIO_NOPULL;
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);


  /* Disable GPIOs clock */
  __HAL_RCC_GPIOA_CLK_DISABLE();
  __HAL_RCC_GPIOB_CLK_DISABLE();

  // STOP Moda girme komutu
  HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
     HAL_Delay(1000);
     SystemClock_Config();

     HAL_Delay(500);
     MX_GPIO_Init();
  MX_USART2_UART_Init();     
}

Outcomes