Monday, 21 January 2013

SD Card Reader with PIC16F1825


I was getting a bit tired of my friend Chris nagging me to hurry up and create some blog posts, and I have been busy with developing my own blog engine that makes use of Markdown, Mono, NoSQL and a number of other technologies. Unfortunately, with how busy life is getting, I don't get enough time to finish it and have other things which are a bit more important (such as my electronics projects). So anyway, this blog will hold as a temporary place holder until I get the time to finish my actual blog, and then redirect all the traffic over to there.

So this post is more of an introduction of what I am working on more than anything else really. Chris Holden created an amazing RAW audio playing device which has essentially only 5 components, as listed here:

  • PIC16F1825
  • 100uF capacitor
  • NPN Transistor
  • SD Card
  • Mini speaker

Obviously there is a power source to take into account, which depending on where you are presenting to the circuit may need a voltage regulator. None the less, it's an amazing little device.

It works on the FAT16 file system, and makes use of SPI to communite to the SD card, along with Pulse Wave Modulation to play the actual audio. Now the FAT16 file system unfortunately has a 4GB disk size limit, but for a lot of simple electronics projects this is more than enough. There is also a a limit of 512 files per folder, which really isn't much of a problem either, however Chris' implementation does not support sub folders. This is where I come in.

I am looking to make a number of changes to this project, and my improvements will be as follows:


  1. Add sub folder support
  2. Get this working with an STA013 to decode MP3 files
  3. Add support for other file systems (perhaps FAT32 or EXT)

Currently on my SD card I am working with the following file structure:



Now I have made a couple small tweaks so far, but nothing major yet. Originally Chris' code did not care if a file was deleted or not, which annoyed me a bit, so was the first tweak I had to make. Now when I query the root directory with UART I see the following:


The first strange thing I found was the "AMyFol" right next to "MYFOLDER". I decided to take a look at the raw hex for the SD card, and I found MyFolder without a problem, however nothing about AMyFol, so something isn't quite right in the code. An extra thing to add to my list of things to check I suppose. For those interested, my hex looked as follows:


So anyway, a number of blog posts are sure to follow whilst I work on this. I am hoping to get the Sub Folder support added very quickly, as I need it for another project I have in mind.

2 comments:

  1. In your raw hex screenshot, look two lines (32 bytes) before your MYFOLDER entry. There you can see aM.y.F.o.l followed by three spaces. My code ignores characters that are non-alpanumeric, which is why it comes back as aMyFol. There's nothing wrong with the code, it's doing exactly what it should!

    Is your card formatted to FAT(16) or FAT32?
    My guess is that this is the FAT32 style entry for a longer file name of MyFolder. FAT32 is a cobble built on top of FAT16, it uses blocks like FAT16 and a sort-of linked list, but adds extra 32-byte lines of data to achieve long file names.

    If your card is formatted using FAT/FAT16 then I can't explain it. Deleted files/folders usually just begin with ? and have their FAT entries reset to 0xFF (so the system can overwrite the data in the corresponding sectors the next time around).

    ReplyDelete
  2. I must be completely blind, because I honestly did not see that aM.y.F.o.l until you pointed it out to me Chris! In which case, I retract my statement. That said, I should perhaps word myself better, as there was nothing wrong with your original code, the problems lie in my modifications!

    My card is formatted to FAT(16), I'm not going to attempt FAT32 until I get sub folders and MP3s working. That said, I received my STA013 chips in the post today. I'll try to solder one to a breakout on Thursday, but meanwhile, I have to work out this sub folder stuff!

    ReplyDelete