Beruflich Dokumente
Kultur Dokumente
1 of 4
http://www.picprojects.net/sdcard_demo/index.html
PICPROJECTS.NET
HOME
PROJECTS
DEVELOPMENT TOOLS
BOOTLOADER
FORUM
DISCLAIMER
PIC PROGRAMMER
SEARCH
Search
Custom Search
Software
Links
PIC PROJECTS
Description
RS232 Communication
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
Hardware
HARDWARE PROJECTS
SD-cards can be interfaced to a microcontroller via SPI-Bus, hence only 4 I/O pins (SDI, SDO, SCK, CS) are required to
ENC28J60 Modul
RS232 Module
SD-cards operate at 2.7V .. 3.6V while the 18F PICs usually operate at 5V. Hence a voltage level translation is required
LCD Adapter
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
DEVELOPMENT TOOLS
PIC C Compiler Overview
PIC Programmer
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.
BOOTLOADER
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
Serial PIC Bootloader
3/17/2015 4:07 PM
2 of 4
http://www.picprojects.net/sdcard_demo/index.html
Here some pictures of the SD-card module which I have build on a breadboard and the experimental setup. I used the
PIC1618Exp-28d experiment board assembled with a PIC18F2620 for the experimental setup.
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.
Modifications in mmcsd.c
Search for
uint32_t g_mmcsdBufferAddress;
and add under it:
uint32_t g_mmcsdPartitionOffset;
Next, just before the "mmcsd_init" function add a new function:
3/17/2015 4:07 PM
3 of 4
http://www.picprojects.net/sdcard_demo/index.html
uint8_t t;
t = g_mmcsd_buffer[off + 4];
if (t == 0x04 || t == 0x06 || t == 0x0B)
{
// FAT16 or FAT32 partition
g_mmcsdPartitionOffset = make32(
g_mmcsd_buffer[off + 11], g_mmcsd_buffer[off + 10],
g_mmcsd_buffer[off + 9], g_mmcsd_buffer[off + 8]) * MMCSD_MAX_BLOCK_SIZE;
}
}
}
In the "mmcsd_init" function, right after the line:
r1 = mmcsd_load_buffer();
Add the lines:
g_mmcsdPartitionOffset = 0;
mmcsd_check_part(0x1EE);
mmcsd_check_part(0x1DE);
mmcsd_check_part(0x1CE);
mmcsd_check_part(0x1BE);
Finally, in the function "mmcsd_move_buffer", after the line:
new_block += g_mmcsdPartitionOffset;
Modifications in mmcsd.c
The CCS "fat.c" functions "get_next_addr" and "get_prev_addr" do not correctly handle cluster transitions. The following
are corrected functions, so replace the function with the following code:
3/17/2015 4:07 PM
4 of 4
http://www.picprojects.net/sdcard_demo/index.html
#ifdef FAT32
Data_Start = Bytes_Per_Cluster + Root_Dir;
#else // FAT16
and replace it with the following code (i.e. remove "Bytes_Per_Cluster +"):
#ifdef FAT32
Data_Start = Root_Dir;
#else // FAT16
And finally, get_short_file_name() needs to be replaced with the following code:
Links
Here some usefull links:
picprojects.net
PIC microcontroller hardware and
software projects with description,
schematics and source code!
Development Tools
Latest Articles
LCD Adapter
RS232 Communication
USB Bootloader
RC5 Decoder
picprojects.net
Serial Bootloader
2011 picprojects.net. Design by Free CSS Templates and Free Web Templates
3/17/2015 4:07 PM