You are on page 1of 10

AN037 Interfacing to an MMC or SD Card via SPI Version 1.

This application note describes an implementation of the multi media card (MMC) interface to the eCOG1k microcontroller, using the SPI bus protocol.

28 January 2008

Cyan Technology Ltd.

AN037

Interfacing to an MMC or SD Card via SPI

Version 1.0

Confidential and Proprietary Information


Cyan Technology Ltd, 2008 This document contains confidential and proprietary information of Cyan Technology Ltd and is protected by copyright laws. Its receipt or possession does not convey any rights to reproduce, manufacture, use or sell anything based on information contained within this document. Cyan TechnologyTM, the Cyan Technology logo and Max-eICETM are trademarks of Cyan Holdings Ltd. CyanIDE and eCOG are registered trademarks of Cyan Holdings Ltd. Cyan Technology Ltd recognises other brand and product names as trademarks or registered trademarks of their respective holders. Any product described in this document is subject to continuous developments and improvements. All particulars of the product and its use contained in this document are given by Cyan Technology Ltd in good faith. However, all warranties implied or expressed, including but not limited to implied warranties of merchantability, or fitness for purpose, are excluded. This document is intended only to assist the reader in the use of the product. Cyan Technology Ltd shall not be liable for any loss or damage arising from the use of any information in this guide, any error or omission in such information, or any incorrect use of the product. This product is not designed or intended to be used for on-line control of aircraft, aircraft navigation or communications systems or in air traffic control applications or in the design, construction, operation or maintenance of any nuclear facility, or for any medical use related to either life support equipment or any other life-critical application. Cyan Technology Ltd specifically disclaims any express or implied warranty of fitness for any or all of such uses. Ask your sales representative for details.

28 January 2008

Cyan Technology Ltd.

Page 2 of 10

AN037

Interfacing to an MMC or SD Card via SPI

Version 1.0

Revision History
Version V1.0 Date 22/03/2006 Notes Initial Version

28 January 2008

Cyan Technology Ltd.

Page 3 of 10

AN037

Interfacing to an MMC or SD Card via SPI

Version 1.0

Contents
1 2 3 4 5 6 Introduction.......................................................................................... 5 Glossary .............................................................................................. 5 MMC and SD Card overview ............................................................... 5 eCOG1k Hardware .............................................................................. 6 The MMC/SD Card Library on the eCOG1k ........................................ 7 Example Software ............................................................................... 7
6.1 6.2 Configuration ............................................................................................. 7 Example Software Operation..................................................................... 7

References .......................................................................................... 8 Application Programming Interface ...................................... 9


void mmcInit(void); .......................................................................................... 9 unsigned int mmcReset(void);......................................................................... 9 unsigned int mmcSendCommand(unsigned int cmd, unsigned long arg); ...... 9 unsigned int mmcRead(unsigned long sector, unsigned char *buffer); ......... 10 unsigned int mmcWrite(unsigned long sector, unsigned char *buffer); ......... 10

Appendix A

28 January 2008

Cyan Technology Ltd.

Page 4 of 10

AN037

Interfacing to an MMC or SD Card via SPI

Version 1.0

1 Introduction

This application note describes an implementation of the multi media card (MMC) interface to the eCOG1k microcontroller using the SPI bus protocol. The application software is based on public ccar6.641 c1l Td(atiodButd-<NU 5(scar6c 6e-2( .0002 agretrolmnt >BDC /TTSp)5(1 Tf-0.3002 Tc -098 90 7386

AN037

Interfacing to an MMC or SD Card via SPI

Version 1.0

4 eCOG1k Hardware

This application note is based on the use of an MMC/SD card interface daughter board, connected to the eCOG1k evaluation board. The daughter board contains a card socket, as well as the necessary connections for monitorinf(s 960.7gol.1.0 )]TJEM/Sp[( /P </MC3D 2 >BDTJ0.2003 Tc -0.6024 T7

R3 Table 1 and

AN037

Interfacing to an MMC or SD Card via SPI

Version 1.0

Port A0 A1 A2

Pin 40 41 42

Operation GPIO0 GPIO1

Function LED0, active low, indicates card in LED1, active low, indicates card locked

AN037

Interfacing to an MMC or SD Card via SPI

Version 1.0

Command i r w

Function Reset and initialise MMC/SD card for operation Read the current sector to the buffer, and display the results

AN037

Interfacing to an MMC or SD Card via SPI

Version 1.0

Appendix A Application Programming Interface


void mmcInit(void); Initialises the MMC/SD SPI card interface, and enables the required signals. Example
mmcInit();

nsigned int mmcReset(void); u Resets the MMC/SD card interface, and configures the device fr efB 17.0sd via SPI

AN037

Interfacing to an MMC or SD Card via SPI

Version 1.0

nsigned int mmcRead(unsigned long sector, nsigned char *buffer); u u Read a block of data from the MMC/SD card into a buffer. Parameters sector *buffer Returns 0 if the read was successful, otherwise returns the response from the MMC/SD card. Example
mmcRead(sector, buffer); // Read the sector to the buffer

The MMC/SD block to read Character pointer to the buffer used to store the read data

nsigned int mmcWrite(unsigned long sector, nsigned char *buffer); u u Write the buffer data to the MMC/SD card block. Parameters sector *buffer Returns 0 if the write was successful, otherwise returns the response from the MMC/SD card. Example
mmcWrite(sector, buffer); // Write the buffer to the specified sector

The MMC/SD block to read Character pointer to the buffer used to store the data to write

28 January 2008

Cyan Technology Ltd.

Page 10 of 10

You might also like