Home Forums Sparkfun MP3 Shield Library Support Forum Interference with millis() function Reply To: Interference with millis() function

#2171
Bill
Member

From the Arduino Reference on attachInterrupt()

Note

Inside the attached function, delay() won’t work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function.

I imagine this is because the user’s function is nested inside the Interrupt vector and therefore global interrupts remain disabled while the user’s function runs. The millis() method uses timer overflow interrupt to increment.

AVRs support nested interrupts. I wonder if there’s any harm in just re-enabling global interrupts first thing in our refill function Michael? Might cause unexpected delays in the SPI stream to the decoder/SD card but that might be tolerable.

Jim, What Michael suggested should work. But if your willing try editing your version of the library as such:

void SFEMP3Shield::refill() {

//Serial.println(F(“filling”));

while(digitalRead(MP3_DREQ)){

to

void SFEMP3Shield::refill() {

sei();

//Serial.println(F(“filling”));

while(digitalRead(MP3_DREQ)){

and you might have to #include <avr/interrupt.h> at the top of the file. See if that breaks anything.