Skip to content

Interfacing a SD card in the SPI mode using a MSP430 as a master device

License

Notifications You must be signed in to change notification settings

jc-SpaceXp/MSP430-SD-SPI

Repository files navigation

Purpose

The idea behind this project was to get some experience using the SPI protocol and using my MSP430

Building Project

Requirements:

  • TI’s open source MSP430-GCC compiler and support files from their website

With the requirements satisfied. It is as simple as:

$ make clean all
$ make clean all DEBUG=1

(With the latter making a DEBUG build for use with GDB)

Logic Analyser Traces

  • This section highlights some minor analysis from my captured signal traces using sigrok/pulseview
  • For these traces I used sparkfuns SD card breakout board with the Samsung Evo Plus 32Gb micro SD card

Init Sequence

traces/screenshots/01_overall.png

  • CS is held high (inactive)
  • MOSI is also held high (giving 0xFF for the byte transmitted)
  • Generated 12 bytes (96 clocks) of transmission
  • This is so the SD card enters SPI mode

Sending CMD 0

traces/screenshots/02_cmd0_transmission.png

  • You can see the complete command and response to/from the SD card in the above picture
  • The SD card (SPI mode) decoder is provided to keep the annotations to a minimum
  • The R1 response is 0x01 indicating the card is in an idle state and therefore initialisation was successful

Sending CMD 8

traces/screenshots/03_cmd8_transmission.png

  • With a R1 response of 0x01 this indicates a V2 spec SD card (as a invalid command would be seen from R1)
  • The last two bytes in the R7 response are the ones we care about (as the reserved bits are zero)
  • We can see they are 0x01 and 0xAA, where 0x01 shows that the current operating voltage is accepted, and 0xAA is simply the echo back of the check pattern from the CMD8 32-bit argument

Sending CMD 58

traces/screenshots/04_cmd58_transmission.png

  • Bits 15-23 are set from the OCR register when looking at MISO line (R3 response is 0x00FF8000)
  • This means that the SD card supports the voltage range of 2.7 to 3.6V
  • Bit 29 isn’t set, meaning this isn’t a UHS-II card (which is expected for the card I’m using, a UHS-I card)

Sending ACMD41

traces/screenshots/05A_cmd55_acmd41_retry.png

  • To send a ACMD command, a CMD55 needs to be sent as the previous command
  • As seen above it has taken us two attempts of the CMD55/ACMD41 pair to confirm the SD card has exited its idle state (bit 0 in R1)
  • For completeness here is a zoomed in image of CMD55

traces/screenshots/05B_cmd55_transmission.png

  • The response of 0x00 is expected
  • For completeness here is a zoomed in image of ACMD41

traces/screenshots/05C_acmd41_transmission.png

  • We set the HCS bit in ACMD41, stating that our card is a SDHC or SDXC card (4Gb to 2Tb cards)
  • The SD card can verify this by sending back the OCR when issuing a CMD58 after initialisation has completed

License

This project is zlib licensed, as found in the LICENSE file.

About

Interfacing a SD card in the SPI mode using a MSP430 as a master device

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published