I’m trying to wake up my device using this sleep mode and a spare pin on the P1.
System.sleep(P1S4, CHANGE, 30);
Wakeup from the pin does not seem to be working.
Does anyone know if interrupts on the spare pins are enabled?
Thanks
I’m trying to wake up my device using this sleep mode and a spare pin on the P1.
System.sleep(P1S4, CHANGE, 30);
Wakeup from the pin does not seem to be working.
Does anyone know if interrupts on the spare pins are enabled?
Thanks
@wesner0019, not sure about the pin name but CHANGE is always tricky to use if you don’t have an external pull-up or down. As for interrupts, I’ll have to dig into the code but it’s a good question!
UPDATE: So the pin designation is correct and I see not reason in the code why an interrupt on that pin can’t be attached. You may want to test that assumption without using sleep just to see if the interrupt fires as expected.
@peekay123, I’ve testing and confirmed the pin works as an interrupt but when using it for system.sleep, I am getting weird behavior, like the system exits sleep immediately once called.
What I notice is that the screen flickers and the device functions normally. There is no external pull-up so, maybe something is causing this pin to fall once system.sleep is called?
pinMode(P1S4, INPUT_PULLUP); // No external pull up
analogWrite(TFT_LED, 0); // turn off backlight to screen
System.sleep(P1S4, FALLING, 30);
delay(200);
Particle.connect();
analogWrite(TFT_LED, 255); //turn on backlight to screen
@wesner0019, try using an external pull-up (eg 10K) and set pinMode to INPUT only. Normally, when an interrupt fires by itself it is a good indication of a floating pin or crosstalk with another pin. What’s connected to the pin?
@peekay123, the pin is connected to a power management IC that has an open drain for Power Good Status (low when external power is connected).
I verified that this pin is being reset or being pulled low during the call of system.sleep for some reason. And in some cases when I call the system.sleep after the timer expired the system resets.
Here’s a screen shot of the trace highlighted.
UPDATE: This trace is really close to a PWM trace that controls the screen brightness.
@wesner0019, which power management IC are you using?
@peekay123, Im using this one:
http://www.digikey.com/product-detail/en/BQ24075RGTT/296-23840-1-ND/1960946
@wesner0019, do you have a pull-up resistor on the PGOOD* line?
[quote=“wesner0019, post:5, topic:19654”]
I verified that this pin is being reset or being pulled low during the call of system.sleep for some reason
[/quote] The PGOOD pin is active LOW to indicate a good source of power when PGOOD* is low when (VBAT + VIN(DT)) < VIN < VOVP
. In other words, the charging power is connected and the battery is present (or not). Outside of this range, the output will be high impedance or go HIGH if you have a pull-up resistor. What were you trying to achieve by having this pin tied to WKP?
[quote=“wesner0019, post:5, topic:19654”]
And in some cases when I call the system.sleep after the timer expired the system resets.
[/quote]I am not sure what you mean by calling system.sleep after the timer expired?
@peekay123, I did not place a pull-up on the PGOOD line as I originally did not plan to use this line as an interrupt.
The PGOOD line is actually tied to P1S4. But my goal is to put the device in stop mode and wake-up with a expired timer or when the PGOOD line goes low (indicating external power is being used an not battery power).
System.sleep(P1S4, FALLING, 30);
What I was trying to say is the system wakes up automatically after the set time for sleep has expired (as above the time system wakes after 30 seconds). I've had a few instances when the system wakes-up from the timer, the system resets it self right after waking up (acting as it was in deep-sleep mode).
@wesner0019, if you want to use PGOOD* to wake from sleep() then you will need an external pull-up (10K - 100K), otherwise P1S4 will be left floating. As for reset after waking from the timer, this will require more investigation. Is it a “real” reset or is there a red RGB LED condition?
@peekay123, I’ll place a pull up on this line and test.
For the reset, it is a real reset where the system code starts from the beginning. I don’t have a RGB on my board so I can verify that aspect.
@wesner0019, the new 0.4.9 firmware now supports event trapping:
https://docs.particle.io/reference/firmware/photon/#system-events
You may want to create a global (and retained) “status” code which you change at different steps of your code. You can then catch the “reset” event and store the status code in another retained var which you can read on bootup and publish/print. This is not as effective as the RGB LED but it should allow you to figure out where the reset event may be occuring.
@peekay123, I’ve hacked a pull-up resistor to the P1S4 line but I am still unable to wake up from a FALLING interrupt during sleep mode.
Do you have any other ideas that I could test?
@wesner0019, without hardware, I am working blindly so here are a few questions:
You need minimal testing code as there may be affects from other parts of your app.
Hey @wesner0019 you might be facing this issue:
https://github.com/spark/firmware/issues/846
Turns out the USB interrupts were waking it up, so this PR will fix it:
https://github.com/spark/firmware/pull/812
Slated for 0.5.x firmware, or you can try compiling with the PR locally.
Answers above
@wesner0019, oops! Got those states reversed! So the first thing to do is to pull in that PR so you can test the fix. Then you can focus on the FALLING trigger on P1S4.
@peekay123, I flashed the develop branch to my P1 and used the below minimum sketch to test the wake-up on interrupt.
below is my code.
#include "application.h"
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
#define powerGoodPin P1S4 //low when good power is applied
#define TFT_LED D2 //Screen brightness control
#define LidSensorPin TX //Button to detect when lid is fully on
boolean sleep = true;
boolean TFTBlink = true;
unsigned long prevTFTLed = 0;
void sleepNow();
void setup(){
Serial.begin(9600);
pinMode(powerGoodPin, INPUT_PULLUP);
pinMode(TFT_LED, OUTPUT);
pinMode(LidSensorPin, INPUT_PULLUP);
digitalWrite(TFT_LED, HIGH);
Particle.connect();
}
void loop() {
if(millis() < 45000){ //to flash the backlight to know if system reset
if(millis() - prevTFTLed >= 500){
if(TFTBlink == TRUE){
digitalWrite(TFT_LED, HIGH);
TFTBlink = FALSE;
} else{
digitalWrite(TFT_LED, LOW);
TFTBlink = TRUE;
}
prevTFTLed = millis();
}
}
if(millis() > 45000 && sleep == true){
sleep = false;
sleepNow();
}
if(Particle.connected() == false && WiFi.connecting() == false){
Particle.connect();
}
}
void sleepNow(){
digitalWrite(TFT_LED, LOW);
delay(20);
//System.sleep(LidSensorPin, FALLING, 15);
System.sleep(powerGoodPin, FALLING, 20);
delay(250);
digitalWrite(TFT_LED, HIGH);
delay(250);
digitalWrite(TFT_LED, LOW);
delay(250);
digitalWrite(TFT_LED, HIGH);
delay(250);
digitalWrite(TFT_LED, LOW);
delay(250);
digitalWrite(TFT_LED, HIGH);
}
@BDub, I complied the development git branch and flashed.
Do you know if I can tell that I flashed the development branch correctly?
Are you aware of anything that would cause the system to reset when the USB is plugged in during sleep? See my previous post?
Thanks
@wesner0019, look at @BDub's post above!