@ScruffR,
OK, I am making progress. Here is what I have done so far:
- Simplified the code, I wrote a sketch specifically to exercise the watchdog timer.
// Test program for Gen3 devices - watchdog for example
#include "Particle.h"
const int wakeUpPin = D8; // This is the Particle Electron WKP pin
const int donePin = A3; // Pin the Electron uses to "pet" the watchdog
const int blueLED = D7; // This LED is on the Electron itself
volatile bool watchdogFlag; // Flag to let us know we need to pet the dog
void setup() {
pinMode(wakeUpPin,INPUT); // This pin is active HIGH
pinMode(blueLED, OUTPUT); // declare the Blue LED Pin as an output
pinResetFast(donePin);
pinMode(donePin,OUTPUT); // On the Boron, commenting out this line puts the device into endless reset cycles
attachInterrupt(wakeUpPin, watchdogISR, RISING); // The watchdog timer will signal us and we have to respond
waitUntil(Particle.connected);
Particle.publish("Startup", "Complete will publish watchdog events",PRIVATE);
}
void loop() {
if (watchdogFlag) {
petWatchdog(); // Watchdog flag is raised - time to pet the watchdog
if (Particle.connected()) {
waitUntil(meterParticlePublish);
Particle.publish("Watchdog","Received Wake Interrupt Petting Now",PRIVATE);
}
}
nonBlockingBlink(500, blueLED);
}
bool meterParticlePublish(void)
{
static unsigned long lastPublish=0; // Initialize and store value here
if(millis() - lastPublish >= 1000) { // Particle rate limits at 1 publish per second
lastPublish = millis();
return 1;
}
else return 0;
}
void petWatchdog()
{
digitalWriteFast(donePin, HIGH); // Pet the watchdog
digitalWriteFast(donePin, LOW);
watchdogFlag = false;
}
void watchdogISR()
{
watchdogFlag = true;
}
// Non-blocking blink function
void nonBlockingBlink(unsigned int period, int pin) {
static unsigned long startTimer = millis();
static bool pinState = false;
if (millis() - startTimer > period) {
pinState = !pinState;
startTimer = millis();
digitalWrite(pin, pinState);
}
return;
}
-
I pulled the Argon and Boron off the carrier board and built a simple circuit with just the watchdog and the device.
-
I was able to get the watchdog to work as expected using this setup. So, I went back to the carrier board and discovered that the ground pour for GND and the timing resistors was floating. Fixing that solved the issue with the constant resets.
Which brings me to the present. I am going to test this for a few days but it seems that the core issue was my screwup on the PCB. Sorry to have wasted your collective time on this.
I did pick up on a code change for the Boron cellular modem so, thank you @ric_hard for that!
Chip