I’m going crazy…I believe that analogReads() are allowed in the SparkIntervalTimer ISR routines because I have seen some examples in topics. But it is not working for me…if I include an anlogRead in the ISR, my Photon goes into continual reset mode (blinking red light), restarts and then back to blinking red light.
I must be doing something really stupid…not unusual. This is my first attempt at interrupts and/or software timers. Thanks in advance for any help!
There is only one line of code in the Interrupt Service Routine. Here is my code that works (incrementer instead of analogRead inside the ISR):
#include "SparkIntervalTimer.h"
#define PUBLISH_TIME 1000
IntervalTimer myTimer;
unsigned long currentMillis, prior_publish_time;
uint16_t recent_sample;
void SampleISR(void);
void setup() {
myTimer.begin(SampleISR, 100, hmSec);
}
void loop() {
currentMillis = millis();
// Print the variable from the Interrupt Service Routine every second
if ((currentMillis - prior_publish_time) >= PUBLISH_TIME) {
Serial.printlnf("recent_sample: %d", recent_sample);
prior_publish_time = currentMillis;
}
}
void SampleISR(void) {
//recent_sample = analogRead(A0); //??????
recent_sample++;
}
But if I switch the recent_sample++ to the commented-out line that includes the analogRead…the device never gets out of reset.
SAMPLE OUTPUT for the incrementer version, successfully increments recent_sample about 20 times per second (every 50ms).
Opening serial monitor for com port: “COM6”
Serial monitor opened successfully:
recent_sample: 1
recent_sample: 20
recent_sample: 40
recent_sample: 60
recent_sample: 80
recent_sample: 100
recent_sample: 119
recent_sample: 139
recent_sample: 159
recent_sample: 179
recent_sample: 199
recent_sample: 218
recent_sample: 238