PIC32MX: Interfacing to a Secure Digital (SD) Flash Card

From Mech
Jump to navigationJump to search

Original Assignment

Do not erase this section!

Your assignment is to create code that will allow the PIC32 to read and write data to a FAT32 SD card. The SD card should be able to be read by a PC after data has been written on it by the PIC32.

Create functions so that it is easy to read, write and initialize the SD card.

Use the example projects in the "Microchip Solutions/USB Device - Mass Storage - SD card data logger" and "Microchip Solutions/USB Device - Mass Storage - SD card reader" folders as a guide.

Use your code to create a folder on the PIC32 and write 1000 bytes of data to a text file in that folder. How long does it take? Make sure the PC can read the file.

Create a folder on the SD card with the PC and place a text file in the folder with 1000 bytes of data. Read the file with the PIC32. How long does it take?

Overview

Secure digital cards, or SD cards, are inexpensive and common mass storage devices that can be interfaced with our PIC to provide a larger nonvolatile data storage space. In this lab, we will interface our PIC 32MX460F512L to communicate with a 2GB FAT32 SD card to allow reading and writing of data. We will do so using SPI mode.

Circuit

The SD card holder has 11 pins with only 6 being directly used for communication with our PIC. The SD card will be powered off 3.3V from our PIC, which will come our mini-usb connection. 10K and 1K resistors are added to allow for a voltage drop for each connection. LEDs are added for the Write Protect (WP) and Card Detect (CD) to see if the card is being read properly externally from the PIC. The LEDs turning on signifies that the card is detected and write protect is off.

EB WF BK Circuit diagram.png

We soldered square pin headers onto the SD card holder to allow easy connection to our breadboard. Please see our circuit below for more detail.


EB WF BK HardwarePic.png

Code

Where possible, make it a single piece of well-commented cut-and-pastable code, or at least make each function that way, so others can easily copy it. Most comments should be in the code itself; outside the code (on the wiki) should only be explanatory comments that are too cumbersome to include in the code.