SD/MMC Card interfacing 

with AVR Micro-controllers

Overview of SD/MMC Cards:

                        Multimedia Cards are one of the smallest Flash cards available, about the size of a postage stamp. A Multimedia Card (MMC) is a tiny memory card that uses flash memory to make storage portable among various devices. Multimedia Cards are much more rugged than traditional storage media. MMC features encryption capabilities for protected content, to ensure secure distribution of copyrighted material. High Speed SD and miniSD cards offer a combination of high storage capacity, great flexibility and security. As an extension of the existing SD card standard, the miniSD card allows cell phone and consumer electronics developers to design much more compact devices. 

 

PIN Diagram:

Table: SPI Mode of MMC

PIN #

NAME

Type / Direction

Description

1

CS

IN

Chip Select

2

DI

IN

DATA In

3

VSS

S

Supply Voltage Ground

4

VDD

S

Supply Voltage

5

SCLK

IN

Clock

6

VSS2

S

Supply Voltage Ground

7

DO

OUT

DATA Out


Interfacing with ATMega 162:

                 It is easy to interface a MMC (Multimedia Card) with an Atmel ATmega162 (AVR series) via the SPI (Serial Port Interface). The MMC is connected to the SPI pins of the ATmega16 via simple resistor voltage dividers to transform the +5V high levels to about 3.3V used by the MMC. If the Atmega-162 is working on 3.3 V power supply then all the MMC pins can be directly connected to Microcontroller (as in this design). The data-out pin from the MMC goes directly to the ATmega162, because 3.3V is high for the ATmega162 anyway. The schematic of the MMC interfacing is given below.

 

 SD/MMC Card Interfacing Function in AVR C:

              Accomplishing the communication between microcontroller and MMC card we need to know about the Protocols supported by devices and interface. Here for MMC we are using SPI interface. All the SPI commands and functions are written into spi.c library file. Including of this file to source code will enable us to perform MMC related task.

 

To work with this library, the card must be wired to the SPI port of the Atmel microcontroller as described below. Typical cards can operate at up to 25MHz maximum SPI clock rate (thus faster than most AVR's maximum SPI clock rate).

 

       1 - CS : (chip select)                  - wire to any available I/O pin(*)

       2 - DIN: (data in, card<-host)    - wire to SPI MOSI pin

       3 - VSS: (ground)                      - wire to ground

       4 – VDD: (power, 3.3V only)   - wire to power (MIGHT BE 3.3V ONLY!)

       5 – SCLK: (data clock)             - wire to SPI SCK pin

       6 – VSS: (ground)                     - wire to ground

       7 – DOUT: (data out, card->host) - wire to SPI MISO pin

 

Function used for this application form this library and their brief description.

void mmcInit   ( void  )                       

            Initialize AVR<->MMC hardware interface. Also prepares hardware for MMC access.

u08 mmcRead ( u32    sector, u08 *   buffer   )                      

            Read 512-byte sector from card to buffer Returns zero if successful.

u08 mmcReset ( void )                       

            Initialize the card and prepare it for use. Returns zero if successful.