Simple SD card to DAC player issues

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Simple SD card to DAC player issues

Jump to solution
1,449 Views
stefandz
Contributor II

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

0 Kudos
Reply
1 Solution
913 Views
stefandz
Contributor II

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!

View solution in original post

0 Kudos
Reply
2 Replies
913 Views
stefandz
Contributor II

I've taken a further look at this and can add the following:

  • it's definitely not the buffer swapping after two fills - I can read inline for three or four consecutive blocks no problem
  • it doesn't appear to be that SPI0 (the bus that the SD card sits on) is being disabled - SPE in SPI0_C1 remains at '1' even after enabling the Audio DAC interrupts

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.

0 Kudos
Reply
914 Views
stefandz
Contributor II

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!

0 Kudos
Reply