dsPIC33FJ and SPI bus SD card communication

Author
antal_peter
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2013/10/27 00:08:03
  • Location: Hungary
  • Status: offline
2018/10/29 23:31:13 (permalink)
0

dsPIC33FJ and SPI bus SD card communication

Based on a traxmod 32 bit PIC audio player, I have made a transcript to dsPIC33FJ256. This solution use a DMA based SPI read routine to read SD card. This solution worked fine until I started to use a Sony 8GB micro SD card instead of 4GB Maxell, what had simple burned out. 
Earlier both card worked fine under windows. So I have made a test program to measure read time of sd card in SPI mode. Meanwhile I get a noname 8Gb micro SD card and I compare the two 8Gb SD card. I started with 2 Mhz clock. The Sony randomly missed the the 30 ms audio buffer timing the noname play well. I raised the SPI clock to around 19 Mhz. The noname 8GB SD worked fine while the Sony made a random misplaying.
My conclusion: The SPI bus design not well defined. It's behavior independent from the "non SPI" behavior.
#1

6 Replies Related Threads

    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2735
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: dsPIC33FJ and SPI bus SD card communication 2018/10/30 05:15:35 (permalink)
    0
    Microchip implements SPI on 100's of chips.  Your conclusion is wrong.
     
    I have had stereo sound at 44.1KHz fetched from an SD card and sent to DACs.
    You need some assembly, more DMA channels and double buffering.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #2
    antal_peter
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2013/10/27 00:08:03
    • Location: Hungary
    • Status: offline
    Re: dsPIC33FJ and SPI bus SD card communication 2018/10/30 11:03:52 (permalink)
    0
    You maybe misunderstood my conclusion. The SPI bus is well defined. The problem is the SD card in SPI mode.
    I made a test: 
    The base of measurement is the "Temptation" wav file 4:45  The spi bus clock: 19Mhz.
    Sony 8 GB 1 block read. 
    read min: 11uS      readmax: 6044uS
     
    No name SD card:
    read min: 43 uS     readmax: 86uS       No playing error
    #3
    Jim Nickerson
    User 452
    • Total Posts : 5447
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: online
    Re: dsPIC33FJ and SPI bus SD card communication 2018/10/30 11:28:16 (permalink)
    0
    In my experience SD cards tend to vary with regards to the timing...
    #4
    du00000001
    Just Some Member
    • Total Posts : 2169
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: dsPIC33FJ and SPI bus SD card communication 2018/10/30 13:07:20 (permalink)
    0
    The Sony might be near end-of-life as well - eventually taking a lot of time for error correction.
    While you might not hear data errors, error correction is really important when it comes to data storage.
    So the Sony card could well be the better product - just not appropriate for your application.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #5
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2735
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: dsPIC33FJ and SPI bus SD card communication 2018/10/30 15:17:37 (permalink)
    0
    Audio should be double buffered.
     
    You could improve the cluster reading from the fat table.
     
    With double buffering and dma:
    1. read from spi to memory.
    2. send the other buffer to dac.
    3. swap buffer pointers.
     
    While one buffer is filling up the other buffer is full and can be played.
    This makes wave files smooth, timing should not be an issue, I have even used 1GB cards and smaller.
     
    post edited by Gort2015 - 2018/10/30 15:19:49

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #6
    antal_peter
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2013/10/27 00:08:03
    • Location: Hungary
    • Status: offline
    Re: dsPIC33FJ and SPI bus SD card communication 2018/11/09 11:42:21 (permalink)
    0
     
    du00000001 has right. I bought a third card. Kingstone 4 GB. It works. 
    The SD read min is: 34 us   the  SD read max is 85 uS
     
    Gort2015
    My solution is double buffered. The audio DMA is in continuous pin-pong mode. The SPI DMA done when the pin-pong buffer changed.
    #7
    Jump to:
    © 2018 APG vNext Commercial Version 4.5