Hi everyone
I’ve been playing with the code from Arduino Data-Logger Shield with the FRDM-KL25Z Board | MCU on Eclipse on the FRDM-KL25Z with the hope of getting something to play from an SD card to the DAC. My chosen format is mono, uncompressed 22.05kHz sampling rate, 16-bit audio which I think has a reasonable chance of being doable with SPI SD card reads and the DAC.
I basically took the previous project and added a TimerInt (which drives the DAC sample output), a DAC and a couple of IO pins which are specific to my setup. Despite having the interrupt driven DAC code and this example working fine, I have problems when tying the two together.
I have a double-buffered setup. I start by filling both buffers from the SD – which works fine. I then enable the audio interrupt which outputs the next sample each time it is called. When it gets to the end of a buffer it swaps the front and back buffers, resets the sample indexer and fills the back buffer from the SD.
However, the third SD read call (the first driven by the audio interrupt) sits waiting forever for SD1_DataReceivedFlag (before you say so, I have of course already got this correctly implemented in events.c otherwise the first read would stall it, not the third). I’ve tried a few things including different buffer sizes (just guessing) and then popped my scope on the SPI pins.
Oddly, the SPI pins work fine for the first two calls (as we should expect, since we get correct returns) and yet they do NOTHING in the third call at all. It’s almost as if SPI is disabled inside the TimerInterrupt…
If anyone could shed some light on this I would be most appreciative. I have attached what I have achieved so far and also a sample "1.raw" file to put on the SD card. I realise that this code is full of holes and will crash hard once the files reaches its end anyway - but I'm sure that's not what's killing it right now.
Alternatively, if anyone knows anyone who does a little freelance consulting who could help me out that would be something I would consider.
By the way, all the Processor Expert Components required to run what I have attached are available at Embedded Components.
Greetings from London
Stefan
Original Attachment has been moved to: Freedom_FatFS.zip
Solved! Go to Solution.
Seems that the problem was I was trying to read from the SD card whilst inside my audio output periodic interrupt. Setting an asynchronous flag and handling it in the main routine sorted me out!
I've taken a further look at this and can add the following:
I'm going to take a look at Erich Styger's later example from GitHub that uses an RTOS. Not sure how or if this will make a difference, but worth taking a look no doubt.
Seems that the problem was I was trying to read from the SD card whilst inside my audio output periodic interrupt. Setting an asynchronous flag and handling it in the main routine sorted me out!