Hot!Need help using FATFS on SDHC w/ PIC32MZ to write Wav file

Author
pooomah
New Member
  • Total Posts : 24
  • Reward points : 0
  • Joined: 2015/04/25 18:04:42
  • Location: 0
  • Status: offline
2017/10/03 17:20:36 (permalink)
0

Need help using FATFS on SDHC w/ PIC32MZ to write Wav file

Hello,
 
I've read through so many of the FATFS/SD threads but cannot seem to find what I need.
 
 
I have developed a SPI driver and I successfully initialie my card and read back the CSD register/etc.  
My SPI/SD access is good.  
 
The application is a data recorder.  Have a 192kHz 24 bit ADC and want to write directly to SD. Never read, write only. FAT file format, Wav file. 
 
In interfacing with elm-chans FATFs, I found that the PIC24 examples were blocking.  That is, a Do() and/or While() at low level functions. For instance, wherever the disk_write() function of diskio.c is called, it is expected to return a successful status, as opposed to a "not ready," or something so it can be polled.  Reading through the PIC24 examples (and other implementations on this forum) also seem to use blocking during SD access.   
 
How am I supposed to do anything if I have to wait during a write?  
 
I think I am missing some understanding about integrating FATFS on a PIC, can anybody help me?
Simply put: How can I write .wav file data as ADC data rolls in? 
I have SPI writes working well, need to integrate a FAT FS that won't block my code. I can't see how to write the function disk_write() without blocking or re-writing higher level functions as well. 
 
Thanks in advance for your help
<3
#1

7 Replies Related Threads

    malaugh
    Super Member
    • Total Posts : 295
    • Reward points : 0
    • Joined: 2011/03/31 14:04:42
    • Location: San Diego
    • Status: offline
    Re: Need help using FATFS on SDHC w/ PIC32MZ to write Wav file 2017/10/03 20:31:18 (permalink)
    3 (1)
    Not an expert on this, but I have used FATFS.  As you say it is a blocking function, only returns after the operation is complete.  I would have thought you could run your ADC sample function as a timer interrupt, filling up a buffer.  Once the buffer is full, switch to an empty buffer for the ADC samples, while you write the full buffer to the SD card.  Continue this way, switching between the two buffers, filling one on the ISR and writing the other one to disk.
    #2
    maxruben
    Super Member
    • Total Posts : 3248
    • Reward points : 0
    • Joined: 2011/02/22 03:35:11
    • Location: Sweden
    • Status: offline
    Re: Need help using FATFS on SDHC w/ PIC32MZ to write Wav file 2017/10/04 08:19:13 (permalink)
    0
    An RTOS may also be of help here.
     
    /Ruben
    #3
    pooomah
    New Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2015/04/25 18:04:42
    • Location: 0
    • Status: offline
    Re: Need help using FATFS on SDHC w/ PIC32MZ to write Wav file 2017/10/04 08:20:04 (permalink)
    0
    malaugh:
    Indeed, that's what i'm going to try to do next.
    I just prefer polling based, easier to test and simpler--in my experience at least.  
     
    I'm hoping for somebody with FAT experience to say "Oh you're just writing FAT files, no need for entire FATFS, it's just this set of writes"
     
    Essentially, I don't understand FATFS enough to make it work myself, and I'm not too happy about interrupting out of a library that I have trouble understanding. 
     
    Wish me luck! :)
    #4
    karan123
    Super Member
    • Total Posts : 714
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: Need help using FATFS on SDHC w/ PIC32MZ to write Wav file 2017/10/04 10:14:01 (permalink)
    0
    Which part to PIC32MZ SHDC you are using?
    #5
    pooomah
    New Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2015/04/25 18:04:42
    • Location: 0
    • Status: offline
    Re: Need help using FATFS on SDHC w/ PIC32MZ to write Wav file 2017/10/04 10:26:33 (permalink)
    0
    karan123
    Which part to PIC32MZ SHDC you are using?



    I'm not sure what you mean? 
    It's a PIC32MZEF2048EFG using SPI1 on a Sandisk SDHC 8GB card and some Sparkfun module to breakout the SD pins.  
     
    SD functions work great now just need the file system. 
    #6
    karan123
    Super Member
    • Total Posts : 714
    • Reward points : 0
    • Joined: 2009/02/02 11:11:21
    • Location: 0
    • Status: offline
    Re: Need help using FATFS on SDHC w/ PIC32MZ to write Wav file 2017/10/04 10:28:05 (permalink)
    0
    Clock Speed of SPI?
    #7
    pooomah
    New Member
    • Total Posts : 24
    • Reward points : 0
    • Joined: 2015/04/25 18:04:42
    • Location: 0
    • Status: offline
    Re: Need help using FATFS on SDHC w/ PIC32MZ to write Wav file 2017/10/07 16:21:59 (permalink)
    0
    karan123
    Clock Speed of SPI?

    Sorry Karan I missed the notification.  I'm running it at 13MHz. 
    #8
    Jump to:
    © 2018 APG vNext Commercial Version 4.5