www.roland-riegel.de

You are here: HomeMMC/SD/SDHC card libraryFAQ

MMC/SD/SDHC card library: Frequently Asked Questions

General

Which cards are supported?

All MMC/SD/SDHC/miniSD/microSD/microSDHC should work, although not all variants have been tested. Some very old (low capacity) cards might be broken as well. Cards with a capacity of 16 MB or less are usually formatted with FAT12, so these are supported in raw mode only, if at all.

What data rates can I expect?

See the benchmark page.

Are there boards available for purchase?

No.

Hardware

Where can I find the schematic?

Get it here.

What if my card socket has no Card-Detect and/or Card-Lock switches?

Change sd_raw_config.h such that it looks like

    #define configure_pin_available() /* nothing */
    #define configure_pin_locked() /* nothing */

    #define get_pin_available() 0
    #define get_pin_locked() 1 

All attempts to write to the card fail, although reading works. What's the problem?

Enable write support within sd_raw_config.h. And probably, your card socket has no Card-lock detection.

The card initialization fails. What can I do?

Usually this is some kind of hardware problem.

What alternatives to resistor level shifting exist?

If you want to use additional devices with SPI or the resistor solution appears too ugly, there are two possibilities. Either operate the whole circuit with a single 3.3V supply and no level shifting at all or use a level shifting IC which interfaces the memory card to the AVR. Depending on your requirements, adequate devices could include MAX3378E, MAX3392E, MAX3395E, 74LVC245 and 74HCT4050 (optionally together with 74HCT125). Please check the datasheets for the required DC/AC characteristics!

Software

What's the software license?

GPLv2 or (for most parts) LGPLv2.1. Before using a file, read its license terms included at the beginning of the file.

What's the programming language used?

It's C, in compliance with the ISO C99 standard.

What are these .patch-files provided?

Those record the source code differences between the old and new release. If you edited your private sd-reader version, it might be easier to apply the patch files using the "patch" utility common on Unix-like systems, rather than manually inserting the changes by hand. For Windows users, the GnuWin32 project provides a port of "patch".

Where can I learn more about the library interface and how to use it?

Look into the HTML documentation provided online or within each source distribution. Also take the provided main.c as an example application and as a starting point.

How do I adapt it to an ATmegaXYZ and my circuit in particular?

Add your MCU-specific pin configuration to sd_raw_config.h. Some commonly used ones are already included.

How do I adapt it to a different MCU clock?

Change the MCU_FREQ variable within the Makefile.

How do I adapt it to some different MCU architecture?

Change sd_raw_init(), sd_raw_send_byte(), sd_raw_rec_byte() within sd_raw.c and the pin definitions within sd_raw_config.h appropriately.

Can the library be used with Arduino?

Yes. I do not have any experience with Arduino myself, but people report that it works with some minor modifications to the library code needed due to some different compiler settings. Please search the web for details.

Can I use software SPI?

Yes, but the code is not prepared for it.

My application crashes somewhere in the lib. Is there some bug hidden?

There might be a bug. Much more likely, however, is that you experience memory problems, especially heap/stack collisions. The crashes can appear everywhere, but typically this is not the place where the real problem is. Try to minimize the size of structures and other memory blocks your application uses. Sum up the amount of memory your application allocates with global and local variables and the memory you allocate dynamically with malloc(). The avr-nm utility also helps a lot here. When called with the "--print-size --size-sort" parameters, it lists all symbols and their code/memory size within the given file. See the avr-libc FAQ and the nm manual for further information.

Opening the FAT filesystem fails. What can I do?

Make sure there is a FAT16 or FAT32 filesystem on the card. This usually isn't possible for old cards with 16 MB or less. For larger ones, format the cards using the OS utilities, like the Windows Explorer, the Unix/Linux mkdosfs command or special SD card format tools.

Writing to the card returns no failure, but when checking the file's content the data is not there. What happens?

For performance reasons, writing to the card is always buffered. Before pulling the card out of its socket (or issuing a reset of the MCU), make sure sd_raw_sync() gets called such that all buffered data is written out to permanent card storage.

Last modification: 10-10-2010 08:47pm