Skip to content

Commit 76c9153

Browse files
committed
Disable interrupts before modifying Tone timer
Fixes #13
1 parent 3792230 commit 76c9153

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cores/arduino/Tone.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
120120
}
121121

122122
// Timer settings -- will be type B
123+
uint8_t status = SREG;
124+
cli();
123125

124126
// Disable for now, set clk according to 'prescaler_needed'
125127
// (Prescaled clock will come from TCA --
@@ -147,6 +149,8 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
147149

148150
// Enable timer
149151
_timer->CTRLA |= TCB_ENABLE_bm;
152+
153+
SREG = status;
150154
}
151155

152156
// pin which currently is being used for a tone

0 commit comments

Comments
 (0)