Open klerone opened 3 years ago
And this is my code that works to wake-up with interrupt to pin PA1 Rising. The code turn on a LED on PA4 for 5 seconds then goes to sleep and wake-up when press the button, then turn on the led again 5 seconds and repeat.
` /**
void LED_Toogle(){
pinMode(LED_Pin, OUTPUT);
togglePin(LED_Pin);
//Restart the clock after awake InternalClocks_Init(); }
void enterStopMode(){ //I dont know what the below line does but decrease the power by 10uA RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); //Turn on the power management clock
//Set the Regulator in Low Power and can be awake by an interrupt PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); }
/*
Set Pins to Analog to decrease power usage */ void setPinsToAnalog(){ pinMode(PA0, INPUT_ANALOG); //pinMode(PA1, INPUT_ANALOG); //If set to analog Interrupt do not work pinMode(PA2, INPUT_ANALOG); pinMode(PA3, INPUT_ANALOG); pinMode(PA4, INPUT_ANALOG); pinMode(PA5, INPUT_ANALOG); pinMode(PA6, INPUT_ANALOG); pinMode(PA7, INPUT_ANALOG);
pinMode(PA9, INPUT_ANALOG); pinMode(PA10, INPUT_ANALOG);
pinMode(PB1, INPUT_ANALOG);
pinMode(PF0, INPUT_ANALOG); pinMode(PF1, INPUT_ANALOG); }
void setup(){ pinMode(LED_Pin, OUTPUT); pinMode(KEY_Pin, INPUT_PULLDOWN); attachInterrupt(KEY_Pin, LED_Toogle, RISING); }
void loop(){ //Just Keep the LED On to measure the running power digitalWrite(LED_Pin, HIGH); delay(5000); digitalWrite(LED_Pin, LOW);
setPinsToAnalog();
enterStopMode();
}
/**
int main(void) { InternalClocks_Init(); //Set the internal clock @ 8MHz Delay_Init(); setup(); for(;;)loop(); } `
Hello @FASTSHIFT have been a long time since opened this to ask, this week i got determined to solve it myself.
Here i share a Low Power library I made putting together code from various tutorials, I include examples too.
this a project file with the library and the example ready. Keilduino F0 Low Power.zip
I helps to easy enter the different modes, auto wakeup with rtc and or interrupt on pin PA0.
just the Sleep mode seems it is not working.
This is the library file LowPower.zip
Hello.
I have been for a while diving in information and looking in the internet before coming to ask.
I am testing out the Low Power Modes in the STM32F03F4P6, at this point I have been able to use the STOPMode and wake-up with a pin Interrupt, in my custom PCB the power goes low to 10uA, really good.
But I want to know how to make it awake every certain amount of time then sleep again, for example to read a sensor, send the data then sleep some minutes and do it again.
I have been trying using the Timer example, not success there. Probably I am missing something important. I read something about this line of code NVIC_SystemLPConfig(NVIC_LP_SLEEPONEXIT, ENABLE); but I really cannot understand the process to follow, if someone can point me in the right direction it will be great.
This is the code I have been trying unsuccessfully.
` #include "Arduino.h"
define LED_Pin PA4
define KEY_Pin PA1
void Timer1_Callback(){ pinMode(LED_Pin, OUTPUT); togglePin(LED_Pin); TIM_Cmd(TIM1, DISABLE); InternalClocks_Init(); //Setup the clock after awake }
void enterStopMode(){ Timer_SetInterrupt(TIM1, 1000000/@1s/, Timer1_Callback); TIM_Cmd(TIM1, ENABLE);
//I dont know what the below line does but decrease the power by 10uA RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); //Turn on the power management clock
//Set the Regulator in Low Power and can be awake by an interrupt PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI); }
//Set Pins to Analog to decrease power usage void setPinsToAnalog(){ pinMode(PA0, INPUT_ANALOG); pinMode(PA1, INPUT_ANALOG); //If set to analog Interrupt do not work pinMode(PA2, INPUT_ANALOG); pinMode(PA3, INPUT_ANALOG); pinMode(PA4, INPUT_ANALOG); pinMode(PA5, INPUT_ANALOG); pinMode(PA6, INPUT_ANALOG); pinMode(PA7, INPUT_ANALOG); pinMode(PA9, INPUT_ANALOG); pinMode(PA10, INPUT_ANALOG); pinMode(PB1, INPUT_ANALOG); pinMode(PF0, INPUT_ANALOG); pinMode(PF1, INPUT_ANALOG); }
void setup(){ pinMode(LED_Pin, OUTPUT); pinMode(KEY_Pin, INPUT_PULLDOWN);
// it is supposed to allow to wakeup with the time but it did not work. NVIC_SystemLPConfig(NVIC_LP_SEVONPEND, ENABLE); }
void loop(){ //Just Keep the LED On to measure the running power digitalWrite(LED_Pin, HIGH); delay(5000); digitalWrite(LED_Pin, LOW);
//Go to Sleep setPinsToAnalog(); enterStopMode(); }
/**
int main(void) { InternalClocks_Init(); //Set the internal clock @ 8MHz Delay_Init(); setup(); for(;;)loop(); } `