Exploring SDCards and how to talk to them (all).
Latest Experimental Code
The first version of the SD Card code I did just supported the 2 1GB disks I had available. The spec actually has lots of branches, and I only implemented what I needed, so this obviously means there are lots of cards that don't work, as reported in the forum. This page will log some of my experiments to expand the support to more cards.
First, lets get one we know works, working...
Using the example in the cookbook, I constructed the simple program and ran it on a board with a known good SD card (Kingston 1GB) on a nice new SD Card testrig:
and got a file on the disk and this in the terminal:
Hello World! Goodbye World!
Note that if the disk is not in, or the wiring is wrong, the result was:
Hello World! Not in idle state Could not open file for write
Now, we collect as many cards as we can find!
The Kingston 1GB is the top left, formatted as FAT.
With the other cards, we get:
- SanDisk TransFlash 256MB - Timeout waiting for card
- SanDisk 2GB - Timeout waiting for card
- Kingston 2GB - Timeout waiting for card
- Hama 128MB - Timeout waiting for card
- Transcend MMCPlus - Timeout waiting for card
- Nothing - Not in idle state
Under the hood, this means it is not successfully getting past the initialisation for most of the cards. Lets investigate...
If you look at the spec, after moving to SPI mode you should send CMD8 - I'd ignored this as it wasn't essential, but it is a way to determine what commands/version the card is. Sending CMD8, I get:
- SanDisk TransFlash 256MB - CMD8 illegal (0x7F)
- SanDisk 2GB - CMD8 illegal (0x7F)
- Kingston 1GB - CMD8 ok
- Kingston 2GB - CMD8 illegal (0x05)
- Hama 128MB - CMD8 illegal (0x05)
- Transcend MMCPlus 512MB - CMD8 illegal (0x05)
Based on Alessandro's comment, I experimented with clocking the card after sending commands and cs has gone high. For the newer cards, these become recognised as version 2.0 rather than failing with a command error.
The program demonstrating that is:
This makes the cards change from a fundamental failure to a "this card tastes funny" which is more about the block sizes. Feel free to run and test. The older cards still timeout, so I think a focus should be doing an official startup first (CMD8, detect pass/fail to determine version 1 or 2 of std):
Here is an updated example that identifies a card as version 1.0 or 2.0 on the terminal:
If you have an SD card, please run this and report back with a photo of the SDCard and the terminal output so we can get an idea of what cards are what version. Still needs to actually implement the rest of the card setup for all versions to make it actually work :)...
Had a bit more of a jack and added support for these other modes, and stopped it bombing out when it thought the block size was too big (was actually the maximum block size).
This code writes a file to every one of my SD cards pictured (not the MMC card!):
Please test it yourself. If it looks like it is working, i'll refactor it to get rid of all the duplicated code.
Please log in to post a comment.