Exercise 10: SD card
This activity is supplementary for those who have a hardware. Unfortunately, SimulIde software does not contain any SD card module, but we encourage you to watch at least the movie to understand the idea.
Main topic:
- SD card
FatFS library
The aim of the exercise is to familiarize the user with the operation of typical SD/MMC cards with the use of the ATmega32 microcontroller. SD cards can be read and written using the fast 4-bit interface as well as the slower method using the SPI bus. This exercise will focus on the second method of saving data on SD card.
Typically SD cards have a FAT32 file system. It is convenient to use a ready-made library to support reading and writing cards along with the FAT32 file system. FatFs is such a library. Description of available functions can be found at: http://elm-chan.org/fsw/ff/00index_e.html.
To use the FatFs library, download and unpack the archive: https://study.engined.eu/mod/url/view.php?id=461 then attach to the Makefile, ff.c and mmc_avr.c files.
There are three objects in the FatFs library:
1. for the file system (FATFS),
2. for a file (FIL),
3. to store the results returned by functions (FRESULT).
The most important functions of the FATFS library are:
1. f_mount - for mounting the SD card
2. f_open - to open a file.
3. f_write - for writing data to a file
4. f_close - to close the file
Detail descriptions are available here: http://elm-chan.org/fsw/ff/00index_e.html