Summary of SD-Card with CCS C Compiler using pic microcontoller
This article details a project interfacing an SD card with a FAT16 file system to a PIC microcontroller using the CCS C compiler. The author modified existing drivers to resolve compatibility issues where files created on the demo were not visible on a PC. Hardware implementation involves SPI communication with voltage level translation from 5V to 3.3V using a 74AC125 buffer instead of resistors for reliability at higher speeds. Software adjustments were made to ensure proper file system recognition by the host computer.
Parts used in the SD-Card with PIC Project:
- SD-card
- PIC microcontroller (18F series)
- 74AC125 buffer
- CCS C compiler
- mmcsd.c driver
- fat.c driver
Description
This project shows how to use a SD-Card with FAT16 file system. It is based on the example MMC/SD-Card driver (mmcsd.c) and FAT file system driver (fat.c) delivered with the CCS C compiler. Unfortunately, the example didn’t work properly for me. So I searched the web and found some required changes to make it work. All modifications are described in the following article.
Hardware
SD-cards can be interfaced to a microcontroller via SPI-Bus, hence only 4 I/O pins (SDI, SDO, SCK, CS) are required to connect the SD-card to the PIC.
SD-cards operate at 2.7V .. 3.6V while the 18F PICs usually operate at 5V. Hence a voltage level translation is required for the SD-card inpus (SDI, SCK, CS). There are a lot of examples available in the web where a voltage divider with resistors is used to translate the 5V signals to 3.3V. This will work, but at higher SPI speeds this might cause problems. Due to that, I used a 74AC125 buffer to do the level translation which works more reliable than the voltage divider.
SD-Card Module
Here the schematic of the SD-Card module with the voltage level translation. The pins on the connector SV1 need to be connected to the microcontroller pins.
Important: SDO and SDI are the pin names from the SD-card point of view, i.e. SDO needs to be connected to SDI on the microcontroller and SDI needs to be connected to SDO in the microcontroller!
Software
As mentioned in the description for this article, I used the ex_fat.c example which is delivered with the CCS C compiler.
Unforunately, when I run the demo and created some files with the demo, I was not able to see the files when I pluged the SD-card into my PC. After some investigations I found a solution for this problem in the CCS forum which I will summarize here.
For more detail: SD-Card with CCS C Compiler
- How is the SD-card connected to the microcontroller?
The SD-card interfaces via the SPI-Bus requiring four I/O pins. - What voltage range do SD-cards operate at?
SD-cards operate between 2.7V and 3.6V. - Why was a 74AC125 buffer chosen over a voltage divider?
A buffer works more reliably than a voltage divider at higher SPI speeds. - Which compiler example was used for this project?
The ex_fat.c example delivered with the CCS C compiler was used. - What problem occurred when running the initial demo?
Files created during the demo were not visible when the SD-card was plugged into a PC. - Where was the solution for the visibility issue found?
The solution was found in the CCS forum. - What are the required pins for connecting the SD-card?
The required pins are SDI, SDO, SCK, and CS. - Does the SDO pin connect directly to the microcontroller SDO?
No, SDO from the card must connect to the microcontroller SDI and vice versa.

