Application Report
SLAA281C – November 2005 – Revised August 2018

Interfacing MSP430™ MCUs With MMC orSD Flash Memory Cards........................................................................................................................ MSP430 Applications
ABSTRACTThis application report and the associated source code files demonstrate a serial peripheral interface (SPI)
between the MSP430F1612 microcontroller (MCU) and an MMC or SD flash memory card that used in
SPI mode. The provided information can be used with any MSP430™ MCU with a hardware SPI interface.
The sample software described
http://www.ti.com/lit/zip/slaa281.

1234inthisapplicationreportcanbedownloadedfromContents
Hardware Description .......................................................................................................
Software Description ........................................................................................................
Function Description .........................................................................................................
3.1
char mmcInit (void); ................................................................................................
3.2
char mmcping(void); ................................................................................................
3.3
void mmcSendCmd (const char cmd, unsigned long data, const char crc); ................................
3.4
char mmcGoIdle(); ..................................................................................................
3.5
char mmcSetBlockLength (const unsigned long); ..............................................................
3.6
char mmcReadBlock(const unsigned long address, const unsigned long count, unsigned char*pBuffer); .............................................................................................................
3.7char mmcWriteBlock (const unsigned long address, const unsigned long count, unsigned char*pBuffer); .............................................................................................................
3.8char mmcReadRegister (const char cmd_register, const unsigned char length, unsigned char*pBuffer); .............................................................................................................
3.9
unsigned long mmcReadCardSize(void); ........................................................................
References ...................................................................................................................

12
3
3
3
3
3
3
3
4
4
4
4

Trademarks
MSP430 is a trademark of Texas Instruments.
All other trademarks are the property of their respective owners.

1Hardware Description
The MSP430F1612 communicates with the MMC or SD card through the SPI interface. SPI is a fast andefficient protocol that allows for simultaneous bidirectional data transfer. Serial data is transmitted andreceived by the MSP430 MCU using the USART module in SPI mode. Figure 1 shows the hardwareinterconnection for the master-slave configuration operating on a single supply voltage.
The associated MSP430F1612 pins P5.3 and P5.4 are configured as GPIO to control the chip-select pin
and read the memory card detect signal. The USART1 hardware peripheral of the MSP430F1612 isconfigured in the 3-pin SPI mode. Pins P5.1, P5.2, and P5.3 of the MSP430 MCU provide the SIMO1,SOMI1, and UCLK1 interface to the MMC card.

SLAA281C – November 2005 – Revised August 2018
Submit Documentation Feedback

Interfacing MSP430™ MCUs With MMC or SD Flash Memory Cards

Copyright © 2005–2018, Texas Instruments Incorporated1

Software Description

www.ti.com
3V
3V
47 kW
MSP430F161x
MMC CardCS
DI
VSS
VCC
SCKCDDO

1P5.02RSTP5.1/SIMO147 kW

34DVCC

100 nF

567P5.3/UCLK1

AVCC
0.1 µF

P5.6
P5.2/SOMI1

DVSS

AVSS

Figure 1. Connection Between MSP430 MCU and MMC Card2

Software Description
The code associated with this application report is designed as a driver set for communication between anMSP430 MCU and an MMC card or an SD card through the SPI bus as described in Section 1. The codeis written modularly and can be reused easily. Only a subset of the available card commands is used,based on the limitations of the SPI interface and the secure functions of the SD card. This sample code
can be downloaded from http://www.ti.com/lit/zip/slaa281.
An example main() function shows the proper use of the driver functions.
1. This function initializes the MSP430F1612 in the 3-pin SPI mode with the function mmcInit().
2. The MCU polls until an MMC card is detected and then tries to read the device memory size.
3. The MCU prepares a buffer with 512 bytes of data and writes it to two different sectors of the card.
4. The MCU reads the data that was written to each memory segment.
Uncomment the following line of code to use the MSP430F1612 DMA module for data transmission
between the MCU and the MMC card, which results in higher communication speed and less CPU load.
//#define withDMA

If you adapt the software to a different USART or a different device in which the USART is connected toother port pins, modify the following functions for the correct settings:• void initSPI (void)• char mmcInit (void)• mmc.h file

2

Interfacing MSP430™ MCUs With MMC or SD Flash Memory Cards

SLAA281C – November 2005 – Revised August 2018
Submit Documentation Feedback

Copyright © 2005–2018, Texas Instruments Incorporated

Function Description

www.ti.com

3

Function Description

3.1

char mmcInit (void);
Initialize the port, SPI, and the MMC card. You might need to adjust this routing if the library to adapt it toanother type of MSP430 MCU or to another USART module. Also, some of the control signals can be set
to a different port, if necessary.
Parameter:
Return:3.2

None
StatusError or success codechar mmcping(void);
Check if MMC card is present.
Parameter:
Return:3.3

None
StatusError or success code

void mmcSendCmd (const char cmd, unsigned long data, const char crc);
Send a command to the MMC card.
Parameter:

Return:3.4

cmddatacrc
None

Command that should be sent to the MMC card
Data for the command
Checksum for the commandchar mmcGoIdle();Set the MMC card in idle mode to save current.
Parameter:
Return:3.5

None
StatusError or success codechar mmcSetBlockLength (const unsigned long);
Set the MMC block length of count = 2n byte. Normally this command is not required. The default block
length is 512 bytes.
Parameter:
Return:3.6

Block Length of count = 2n Byte
StatusError or success codechar mmcReadBlock(const unsigned long address, const unsigned long count,unsigned char *pBuffer);#define mmcReadSector(sector, pBuffer) mmcReadBlock(sector × 512, 512, pBuffer)
Read a size byte big block beginning at the address.
Parameter:

Return:address
countpBuffer
StatusStart address of data to read on the card
Number of bytes to read
Pointer to read buffer
Error or success code

SLAA281C – November 2005 – Revised August 2018
Submit Documentation Feedback

Interfacing MSP430™ MCUs With MMC or SD Flash Memory Cards

Copyright © 2005–2018, Texas Instruments Incorporated

3Function Description

3.7

www.ti.com

char mmcWriteBlock (const unsigned long address, const unsigned long count,unsigned char *pBuffer);#define mmcWriteSector(sector, pBuffer) mmcWriteBlock(sector × 512, 512,pBuffer).
Write a 512-byte big block beginning at the (aligned) address
Parameter:

Return:3.8address
count
pBuffer
StatusStart address of data to write on the card
Number of bytes to write
Pointer to write buffer
Error or success codechar mmcReadRegister (const char cmd_register, const unsigned char length,unsigned char *pBuffer);
Read the register arg1 with length arg2 (into the buffer).
Parameter:

Return:3.9

cmd_register
lengthpBuffer
StatusRegister to read
Number of bytes to read
Pointer to read buffer
Error or success code

unsigned long mmcReadCardSize(void);
Read the card size from the CSD register.
Parameter:
Return:4None
Detected card size

References
1. MSP430F15x, MSP430F16x, MSP430F161x Mixed-Signal Microcontrollers
2. MSP430x1xx Family User’s Guide
3. SanDisk MultiMediaCard Product Manual (SanDisk, 2001)

4

Interfacing MSP430™ MCUs With MMC or SD Flash Memory Cards

SLAA281C – November 2005 – Revised August 2018
Submit Documentation Feedback

Copyright © 2005–2018, Texas Instruments Incorporated

Revision History

www.ti.com

Revision History
NOTE: Page numbers for previous revisions may differ from page numbers in the current version.
Changes from March 14, 2008 to August 24, 2018 ......................................................................................................... Page•

Editorial and format changes throughout document .................................................................................. 1

SLAA281C – November 2005 – Revised August 2018
Submit Documentation FeedbackCopyright © 2005–2018, Texas Instruments Incorporated

Revision History

5

IMPORTANT NOTICE FOR TI DESIGN INFORMATION AND RESOURCES
Texas Instruments Incorporated (‘TI”) technical, application or other design advice, services or information, including, but not limited to,reference designs and materials relating to evaluation modules, (collectively, “TI Resources”) are intended to assist designers who aredeveloping applications that incorporate TI products; by downloading, accessing or using any particular TI Resource in any way, you(individually or, if you are acting on behalf of a company, your company) agree to use it solely for this purpose and subject to the terms ofthis Notice.
TI’s provision of TI Resources does not expand or otherwise alter TI’s applicable published warranties or warranty disclaimers for TI
products, and no additional obligations or liabilities arise from TI providing such TI Resources. TI reserves the right to make corrections,enhancements, improvements and other changes to its TI Resources.
You understand and agree that you remain responsible for using your independent analysis, evaluation and judgment in designing yourapplications and that you have full and exclusive responsibility to assure the safety of your applications and compliance of your applications(and of all TI products used in or for your applications) with all applicable regulations, laws and other applicable requirements. You
represent that, with respect to your applications, you have all the necessary expertise to create and implement safeguards that (1)anticipate dangerous consequences of failures, (2) monitor failures and their consequences, and (3) lessen the likelihood of failures thatmight cause harm and take appropriate actions. You agree that prior to using or distributing any applications that include TI products, youwill thoroughly test such applications and the functionality of such TI products as used in such applications. TI has not conducted anytesting other than that specifically described in the published documentation for a particular TI Resource.
You are authorized to use, copy and modify any individual TI Resource only in connection with the development of applications that include
the TI product(s) identified in such TI Resource. NO OTHER LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE TOANY OTHER TI INTELLECTUAL PROPERTY RIGHT, AND NO LICENSE TO ANY TECHNOLOGY OR INTELLECTUAL PROPERTYRIGHT OF TI OR ANY THIRD PARTY IS GRANTED HEREIN, including but not limited to any patent right, copyright, mask work right, orother intellectual property right relating to any combination, machine, or process in which TI products or services are used. Information
regarding or referencing third-party products or services does not constitute a license to use such products or services, or a warranty orendorsement thereof. Use of TI Resources may require a license from a third party under the patents or other intellectual property of thethird party, or a license from TI under the patents or other intellectual property of TI.
TI RESOURCES ARE PROVIDED “AS IS” AND WITH ALL FAULTS. TI DISCLAIMS ALL OTHER WARRANTIES ORREPRESENTATIONS, EXPRESS OR IMPLIED, REGARDING TI RESOURCES OR USE THEREOF, INCLUDING BUT NOT LIMITED TOACCURACY OR COMPLETENESS, TITLE, ANY EPIDEMIC FAILURE WARRANTY AND ANY IMPLIED WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUALPROPERTY RIGHTS.
TI SHALL NOT BE LIABLE FOR AND SHALL NOT DEFEND OR INDEMNIFY YOU AGAINST ANY CLAIM, INCLUDING BUT NOTLIMITED TO ANY INFRINGEMENT CLAIM THAT RELATES TO OR IS BASED ON ANY COMBINATION OF PRODUCTS EVEN IFDESCRIBED IN TI RESOURCES OR OTHERWISE. IN NO EVENT SHALL TI BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL,COLLATERAL, INDIRECT, PUNITIVE, INCIDENTAL, CONSEQUENTIAL OR EXEMPLARY DAMAGES IN CONNECTION WITH ORARISING OUT OF TI RESOURCES OR USE THEREOF, AND REGARDLESS OF WHETHER TI HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
You agree to fully indemnify TI and its representatives against any damages, costs, losses, and/or liabilities arising out of your noncompliance with the terms and provisions of this Notice.
This Notice applies to TI Resources. Additional terms apply to the use and purchase of certain types of materials, TI products and services.
These include; without limitation, TI’s standard terms for semiconductor products http://www.ti.com/sc/docs/stdterms.htm), evaluation
modules, and samples (http://www.ti.com/sc/docs/sampterms.htm).

Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2018, Texas Instruments Incorporated