Troubleshooting ATTiny2313 + Dataflash audio

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi folks. Long time lurker, first time poster here. Forgive my ignorance, as I'm struggling up the learning curve from Arduino-hacker to AVR novice.

I'm working on a project to play audio samples stored on Dataflash, using an ATTiny2313. My efforts are based on a project kindly posted to Github by @makapuf and described here: http://s3-eu-west-1.amazonaws.co...

I have managed to get my 8-bit WAV audio samples written onto the Dataflash, and I can even get them to play (sort of) using the 2313. But it seems like the timing or interrupts are wrong: it is as if the code is not waiting for the sound to end, and getting ahead of itself. My debugging skills and resources are near zero. I'm trying to use unique sounds and a blinking LED to figue out what's going on. It seems like the wait_snd() function within the play() function is failing to do its job. Beyond that, I'm at a loss to figure out how to troubleshoot this.

The code is here, most notably:
https://github.com/cbonsig/2313g...
and
https://github.com/cbonsig/2313g...

I've also made a video that demonstrates what happens when the code runs. An NTSB-cockpit-voice-recorder style transcript of audio and LED blinks is below. What "should" happen is that it should speak "one", "two", ... "eight", then blink-1x and speak "one", blink-2x and speak "two" and so on... then blink-1x and play QTR1 sound, blink-2x and play QTR-2 sound, etc... Instead, I get this:

http://www.youtube.com/watch?v=k...

0:00 Start of recording
0:01
0:02 Power up // LED solid on
0:03 "Z-ro" (click) // LED solid on
0:04 "O-ne". "T-wo" (click) // LED solid on
0:05 "T-hree". (click) "F.our" (click)(click)
0:06 "(z)ero" (click)
0:07 // LED off
0:08 // LED Blink-2x
0:09 "o(ne)" // LED Blink-3x
0:10 "one"
0:11 // LED Blink-4x
0:12
0:13 // LED Blink-5x
0:14 "two"
0:15 // LED Blink-6x
0:16 "thre(e)"
0:17 // LED Blink-7x
0:18 "?"
0:19
0:20 // LED Blink-8x
0:21 "fou(r)"
0:22
0:23 // LED Blink-9x
0:24 "?" // LED Blink-1x
0:25 (partial CHIME)
0:26 (continue CHIME)
0:27 (continue CHIME)
0:28 (begin QTR-1 sound)
0:29 (continue QTR-1 sound)
0:30 (continue QTR-1 sound)
0:31 (continue QTR-1 sound)
0:32 (continue QTR-1 sound)
0:33 // LED Blink-1x
0:34 // LED Blink-4x
0:35
0:36 // LED Blick-1x
0:37 "(ei)ght"
0:38 "nine"
0:39
0:40 (partial CHIME)

It goes on from there.

Any suggestions on how to figure out what's wrong, or how to fix it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sounddata_length is a shared variable by the looks and since it is uint16, it consists of two bytes. What would happen if the isr kicks in between reading / writing these two bytes? Since your isr will modify the value, strange things will happen. You need to ensure atomic access to this variable. See my tutorial 'the traps when using interrupts'

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Kartman: I found your tutorial here https://www.avrfreaks.net/index.p... ... thanks for the advice, and helping to demystify interrupts. I look forward to giving this a try, and will report back on what I find.