Saturday, 21 January 2017

SD cards for microcontrollers

Getting SD cards that work consistently well with microcontrollers is pretty tricky these days. As users demand larger and larger volumes, the smaller, FAT16-compatible drives are becoming increasingly difficult to source.

Not that they're not out there.
Just that it's a bit of a minefield getting ones that work with a microcontroller - especially if it's for a pre-built module with slightly flaky firmware (I'm looking at you, WTV020 ad4 audio playback device!)

A few years ago, we built our own audio playback module. We documented quite extensively how to make SD cards work with a microcontroller. And just about every SD card pre-built module seems to work within the same parameters as ours:

FAT16 support means cards not bigger than 4Gb
Some Windows machines won't format 4Gb into less than 32kb clusters, so the actual maximum size is more like 2Gb.
A lot of 2Gb cards simply won't initialise in SPI mode, so stick to 1Gb max.
Most unbranded SD cards simply won't initialise in SPI mode - it's part of the SD card specification, but cheap suppliers sometimes don't support this backwards compatibility

We managed to snag a load of assorted SD cards off eBay - they worked out at less than a quid a go, so were pretty good value for money.


We freshly formatted each card, to use FAT16 and 16kb allocation units.


Except, of course, that not all of them worked in our audio playing device

(our device is not much more than an Arduino Pro Mini with a WTV020 sound module mounted directly on top of it)

Strangely, manufacturers that worked at smaller capacities didn't work at 512Mb. For example, when we first built the devices, we tried them out with an assortment of 128Mb and 256Mb SD cards. The only cards that consistently worked were Nokia and/or Sandisk branded.

Unbranded cards simply wouldn't initialise.
So we were surprised to find today that neither our Nokia 512Mb nor our Sandisk TransFlash 512Mb SD cards would boot up. But - strangely enough - unbranded cards (which ordinarily we'd avoid as they almost always fail to initialise) work perfectly.

Which goes to show - there's no rhyme or reason to which cards you should choose for your microcontroller projects. Don't just stick to one brand and assume the same manufacturers cards will work in a variety of different sizes/capacities. Similarly, don't assume that all unbranded disks will fail.

In short, you'll have to take a punt and hope you get lucky!