Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

MultiMedia and SD Flash Card Interface (mmc.c)
[Drivers (for external hardware)]

Detailed Description

 #include "mmc.h" 
This library offers some simple functions which can be used to read and write data on a MultiMedia or SecureDigital (SD) Flash Card. Although MM and SD Cards are designed to operate with their own special bus wiring and protocols, both types of cards also provide a simple SPI-like interface mode which is exceptionally useful when attempting to use the cards in embedded systems.
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 2 3 4 5 6 78 |	<- view of MMC/SD card looking at contacts
   	    / 9                |	Pins 8 and 9 are present only on SD cards
   	    |    MMC/SD Card   |
   	    |                  |
   	    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
(*) you must define this chip select I/O pin in mmcconf.h
 This code is currently below version 1.0, and therefore is considered
    to be lacking in some functionality or documentation, or may not be fully
    tested.  Nonetheless, you can expect most functions to work.


#define MMC_GO_IDLE_STATE   0
 initialize card to SPI-type access
#define MMC_SEND_OP_COND   1
 set card operational mode
#define MMC_SEND_CSD   9
 get card's CSD
#define MMC_SEND_CID   10
 get card's CID
#define MMC_SEND_STATUS   13
#define MMC_SET_BLOCKLEN   16
 Set number of bytes to transfer per block.
 read a block
#define MMC_WRITE_BLOCK   24
 write a block
#define MMC_PROGRAM_CSD   27
#define MMC_SET_WRITE_PROT   28
#define MMC_CLR_WRITE_PROT   29
#define MMC_SEND_WRITE_PROT   30
#define MMC_TAG_SECTOR_END   33
#define MMC_UNTAG_SECTOR   34
 Sets beginning of erase group (mass erase).
 Sets end of erase group (mass erase).
 Untag (unset) erase group (mass erase).
#define MMC_ERASE   38
 Perform block/mass erase.
#define MMC_CRC_ON_OFF   59
 Turns CRC check on/off.
#define MMC_R1_BUSY   0x80
 R1 response: bit indicates card is busy.
#define MMC_R1_PARAMETER   0x40
#define MMC_R1_ADDRESS   0x20
#define MMC_R1_ERASE_SEQ   0x10
#define MMC_R1_COM_CRC   0x08
#define MMC_R1_ILLEGAL_COM   0x04
#define MMC_R1_ERASE_RESET   0x02
#define MMC_R1_IDLE_STATE   0x01
 when received from card, indicates that a block of data will follow
 when sent to card, indicates that a block of data will follow
#define MMC_DE_MASK   0x1F
#define MMC_DE_ERROR   0x01
#define MMC_DE_CC_ERROR   0x02
#define MMC_DE_ECC_FAIL   0x04
#define MMC_DE_OUT_OF_RANGE   0x04
#define MMC_DE_CARD_LOCKED   0x04
#define MMC_DR_MASK   0x1F
#define MMC_DR_ACCEPT   0x05
#define MMC_DR_REJECT_CRC   0x0B


void mmcInit (void)
u08 mmcReset (void)
u08 mmcSendCommand (u08 cmd, u32 arg)
u08 mmcRead (u32 sector, u08 *buffer)
u08 mmcWrite (u32 sector, u08 *buffer)
u08 mmcCommand (u08 cmd, u32 arg)

Function Documentation

u08 mmcCommand u08  cmd,
u32  arg

Internal command function. Issues a generic MMC command as specified by cmd and arg.

Definition at line 189 of file mmc.c.

void mmcInit void   ) 

Initialize AVR<->MMC hardware interface. Prepares hardware for MMC access.

Definition at line 40 of file mmc.c.

u08 mmcRead u32  sector,
u08 *  buffer

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

Definition at line 116 of file mmc.c.

u08 mmcReset void   ) 

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

Definition at line 49 of file mmc.c.

u08 mmcSendCommand u08  cmd,
u32  arg

Send card an MMC command. Returns R1 result code.

Definition at line 102 of file mmc.c.

u08 mmcWrite u32  sector,
u08 *  buffer

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

Definition at line 147 of file mmc.c.

Generated on Sun Oct 29 03:41:09 2006 for Procyon AVRlib by  doxygen 1.4.2