I took a deep dive into SD cards

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As the thread title says, I finally took a deep dive last week into interfacing an SD card to an AVR mega. After studying the SD card specification (which is surprisingly only 263 pages!), it became much less daunting.

 

I got it interfaced via SPI, started getting the initialization procedure working, and then finally reading block data. Once I had that going, I got Elm Chan's FatFs going to read files. I now have 16 KHz audio playing from an unsigned wav file. There's still implementation details missing; it doesn't handle SDSC cards yet (slightly different initialization procedure) and does not handle file writing.

 

I felt more accomplished after getting it working (it was not without it's problem, though).

My digital portfolio: www.jamisonjerving.com

My game company: www.polygonbyte.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jamison wrote:
it doesn't handle SDSC cards yet (slightly different initialization procedure)
Surely recent versions of FatFs have a disk_initialize that works for SDHC as well as "normal" ?

 

Same for writing - it's just an option you turn on in ffconf.h

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Surely recent versions of FatFs have a disk_initialize that works for SDHC as well as "normal" ?

FatFs itself does not actually provide the implementations for disk_initialize, disk_read/write, etc. since it is intended to be platform agnostic.

They do, however, have sample projects with implementations for many different microcontrollers.

 

I like to get my hands dirty and it really didn't eat too much time. A couple more hours and I would have the rest of implementation. If it would have taken weeks to figure out, I wouldn't have wrote it myself. Anything I can spend time learning to do is time well spent.

My digital portfolio: www.jamisonjerving.com

My game company: www.polygonbyte.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jamison wrote:
FatFs itself does not actually provide the implementations for disk_initialize, disk_read/write, etc. since it is intended to be platform agnostic.
Of course it does - you downloaded the wrong file! Don't get ffNN.zip get ffasmple.zip which has implementations for AVR etc - it's all done there for you.

 

The one thing missing recently is that ffsample.zip in previous versions (in the avr_complex directory) had an mmc_avr.c file that then went missing in later versions - so just skip back to an older version to get that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Of course it does - you downloaded the wrong file! Don't get ffNN.zip get ffasmple.zip which has implementations for AVR etc - it's all done there for you.

And repeating what I said in my last post, they do have sample projects. That is what you are talking about there.

 

But where is the harm in learning to implement such functionality myself? Advancing knowledge is never a bad thing. Communicating with an SD card is really no different than Flash memory. Once you get your head wrapped around the command and response protocol, it's not that crazy.

My digital portfolio: www.jamisonjerving.com

My game company: www.polygonbyte.com