Full Version : MMD/SD FAT16 Memory Card Reader (AVR)
avr >>TECHNICAL & HARDWARE >>MMD/SD FAT16 Memory Card Reader (AVR)


AVR_Admin- 05-04-2006
MMC/SD card reader example application
This project is a small test application which implements read and write support for MMC and SD cards.

It includes

low-level MMC read/write routines
partition table support
a simple FAT16 read/write implementation

The circuit

The curcuit board is a self-made and self-soldered board consisting of a single copper layer and standard DIL components, except of the MMC/SD card connector.

The connector is soldered to the bottom side of the board. It has a simple eject button which, when a card is inserted, needs some space beyond the connector itself. As an additional feature the connector has two electrical switches to detect wether a card is inserted and wether this card is write-protected.

I used two microcontrollers during development, the Atmel ATmega8 with 8kBytes of flash, and its pin-compatible alternative, the ATmega168 with 16kBytes flash. The first one is the one I started with, but when I implemented FAT16 write support, I ran out of flash space and switched to the ATmega168.

The software

The software is written in pure standard ANSI-C. Sure, it might not be the smallest or the fastest one, but I think it is quite flexible.

I implemented a simple command prompt which is accessible via the UART. With commands similiar to Unix you can browse different directories, read and write files, create new ones and delete them again, and browse different directories.

The following table shows some typical code sizes in bytes:

layer code size static RAM usage
MMC/SD (read-only) 1002 0
MMC/SD (read-write) 1178 516
Partition 382 0
FAT16 (read-only) 3414 0
FAT16 (read-write) 6412 0

The static RAM in the read-write case is used for buffering memory card access. Without this buffer, implementation would have been much more complicated.

Please note that the numbers above do not include the C library functions used, e.g. malloc()/free() and some string functions. These will raise the numbers somewhat if they are not already used in other program parts.

When opening a partition, filesystem, file or directory, a little amount of dynamic RAM is used, as listed in the following table.

descriptor dynamic RAM
partition 15
filesystem 26
file 51
directory 47

Adapting the software to your needs

The only hardware dependent part is the communication layer talking to the memory card. The other parts like partition table and FAT16 support are completely independent, you could use them even for managing Compact Flash cards or standard ATAPI hard disks.

By changing the MCU* variables in the Makefile, you can use other Atmel microcontrollers or different clock speeds. You might also want to disable write support completely by changing the corresponding defines in the sd_raw_config.h and fat16_config.h files.

Link to Project: http://www.roland-riegel.de/sd-reader/index.html


Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.