SD-Card with CCS C Compiler using pic microcontoller
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.
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.
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!
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
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
Cheapest PCB Prototype: Only $2 for 10pcs 10×10cm PCBs, 24 hours Quick Turn, DHL Delivery in 3 Days
Current Project / Post can also be found using:
- PİC sd kart ccs c