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();
} `