Open
Description
- Hardware: Wemos D1mini ESP8266
- Core Version: latest github.com/esp8266/Arduino as at 9Jun20 midday GMT
- Development Env: Arduino IDE v1.8.12
- Operating System: Windows
- Module: "Lolin(Wemos) D1 R2 & Mini" (all other settings default)
Issue:
After issuing a “tone(D1,1550); delay(500); noTone(D1);” sequence, you can no longer use timer1 (I suspect as something to do with the tone-interrupt still using it)?
I note that the below 2 issues/commits do not appear to have effected/fixed this:
- Turn off IRQ on stopWaveform after Tone timeout Turn off IRQ on stopWaveform after Tone timeout #7232
- Waveform stopped by runtime limit in iSR doesn't deinit the timer Waveform stopped by runtime limit in iSR doesn't deinit the timer #7236
Below is an example sketch:
#define Hz 1200
#define count_80MHz ((80000000/16)/Hz)
volatile boolean pip_now=false;
void ICACHE_RAM_ATTR timer_callback(void) {
static uint16_t isr_loop_debug=0; isr_loop_debug++;
if (isr_loop_debug>(4*Hz)) {isr_loop_debug=0; pip_now=true;} // every 4sec
timer1_write(count_80MHz);
}
void setup() {
Serial.begin(74880);
Serial.println("\nStart");
// comment out the below 'tone(D1,1550)' line, and this sketch will work!
Serial.println("Using 'tone' (this line blocks timer1 so it can't be used again)");
tone(D1,1550);
delay(500); noTone(D1); // Note that "noTone()" on its own [without a proceeding "tone()"] does NOT block timer1
// startWaveform(D1, 100000, 100000, 0); delay(500); stopWaveform(D1); // this also blocks timer1 [same as "tone()"]
Serial.println("Enable timer1 (you should see 'pip' every 4 seconds)");
// xt_rsil(15); // level 15 will disable ALL interrupts // BUT does not disable timer1-interrupts
// setTimer1Callback(nullptr); // has no apparent effect (needs: #include "core_esp8266_waveform.h")
// os_timer_disarm(nullptr); // just crashes esp8266
timer1_disable();
timer1_detachInterrupt();
timer1_attachInterrupt(timer_callback);
timer1_isr_init();
timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE);
timer1_write(count_80MHz);
Serial.println("End of Setup");
}
void loop() {
if (pip_now) {pip_now=false; Serial.println("pip");}
delay(100);
}
Metadata
Metadata
Assignees
Labels
No labels