Skip to main content
Explorer
August 22, 2019
Question

Cannot reach the low power consumption target

  • August 22, 2019
  • 0 replies
  • 699 views

Hello,

I'm starting to use the STM8L family and in particular the STM8L050 MCU. I want to start with low power so i wrote this piece of code :

/* MAIN.C file
 * 
 * Copyright (c) 2002-2005 STMicroelectronics
 */
#include <stdint.h>
#include "stm8l.h"
 
 
#define LED1_PORT PC
#define LED1_PIN PIN1
 
#define LED2_PORT PA
#define LED2_PIN PIN3
 
#define LED3_PORT PB
#define LED3_PIN PIN6
 
#define LED4_PORT PB
#define LED4_PIN PIN3
 
/* Simple busy loop delay */
void delay(unsigned long count)
{
 while (count--)
				nop();
}
 
void init_gpio(void)
{
 /* GPIO setup */
/*
 // Set pin data direction as output
 PORT(LED1_PORT, DDR) |= LED1_PIN; // i.e. PB_DDR |= (1 << 5);
 // Set pin as "Push-pull"
 PORT(LED1_PORT, CR1) |= LED1_PIN; // i.e. PB_CR1 |= (1 << 5);
*/
 PORT(LED2_PORT, DDR) |= LED2_PIN; // i.e. PB_DDR |= (1 << 5);
 // Set pin as "Push-pull"
 PORT(LED2_PORT, CR1) |= LED2_PIN; // i.e. PB_CR1 |= (1 << 5);
		
/*
 PORT(LED3_PORT, DDR) |= LED3_PIN; // i.e. PB_DDR |= (1 << 5);
 // Set pin as "Push-pull"
 PORT(LED3_PORT, CR1) |= LED3_PIN; // i.e. PB_CR1 |= (1 << 5);
		
		
 PORT(LED4_PORT, DDR) |= LED4_PIN; // i.e. PB_DDR |= (1 << 5);
 // Set pin as "Push-pull"
 PORT(LED4_PORT, CR1) |= LED4_PIN; // i.e. PB_CR1 |= (1 << 5);
*/
}
 
main()
{
		// Secure delay for flashing
		delay(100000L);
	
	
 /* Set clock to full speed (16 Mhz) */
 //CLK_CKDIVR = 0;
 
		init_gpio();
 
		while(1) {
 // LED on
				
 PORT(LED2_PORT, ODR) |= LED2_PIN; // PB_ODR |= (1 << 5);
 delay(10000L);
 // LED off
 PORT(LED2_PORT, ODR) &= ~LED2_PIN; // PB_ODR &= ~(1 << 5);
 delay(10000L);
				
				// enter SLEEP mode 				
				wfi();
 }
}

But it seems to go in sleep mode but i cannot reach the current target. I'm still consuming arround 330mA and i don't know why. Am i missing something with the clock ?

Here is my schematics which is very simple as well. I only soldered the MCU with the decoupling capacitors.

If you have any indication, feel free to share.

Best regards,

Aurélien

    This topic has been closed for replies.