The idea behind this project was to get some experience using the SPI protocol and using my MSP430
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)
- 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
- 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
- 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
- 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
- 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)
- 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
- The response of 0x00 is expected
- For completeness here is a zoomed in image of ACMD41
- 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
This project is zlib licensed, as found in the LICENSE file.