(10 intermediate revisions by the same user not shown)
Line 5: Line 5:
  
 
=References=
 
=References=
Thanks Mr. C.C. Dharmani for the SD Card driver libararies.<br>
 
 
The original SD card library for AVR controllers can be downloaded from http://www.dharmanitech.com/.<br>
 
The original SD card library for AVR controllers can be downloaded from http://www.dharmanitech.com/.<br>
 
These libraries have been modified to provide the standard interfaces like File_Write/File_read and also supports multiple file access.<br>
 
These libraries have been modified to provide the standard interfaces like File_Write/File_read and also supports multiple file access.<br>
Line 17: Line 16:
 
The number of files to be handled simultaneously can be configured in fat32.h using the constant C_MaxFilesOpening_U8. <br>
 
The number of files to be handled simultaneously can be configured in fat32.h using the constant C_MaxFilesOpening_U8. <br>
 
To print the debug messages set FAT32_DEBUG_ENABLE to 1.<br>
 
To print the debug messages set FAT32_DEBUG_ENABLE to 1.<br>
 +
<br><br>
 +
 +
=Limitations and Warning=
 +
The file name should max 11-chars including the file type.<br>
 +
<font color="red">There are chances of SD card getting corrupted if the libraries are not used properly.<br>
 +
Below are some tips to avoid the sd card corruption.</font>
 +
#Ensure the file is terminated with EOF before closing.
 +
#Do not disconnect the SD card until the files are closed in software.
 +
#While writing the data to file. Open the file, write the data and close it. Ensure these steps are followed in one go.
 
<br><br>
 
<br><br>
  
Line 43: Line 51:
  
 
=Formatting SD Card=
 
=Formatting SD Card=
As this Sd Crad library is for fat32, the card needs to be formatted using fat32 settings as shown below.<br>
+
As this Sd Crad library is for fat32, the card needs to be formatted using fat32 settings as shown below.
 +
<br><br>
 
[[File:Fat32Formatting.png]]
 
[[File:Fat32Formatting.png]]
 +
<br><br>
  
 
=Connection Diagram=
 
=Connection Diagram=
  
 
=code=
 
=code=
 +
Below example shows the usage of all the fat32 functions.
 +
<html>
 +
<script src="https://gist.github.com/SaheblalBagwan/b1d8a48c52295019777591a7600ad596.js"></script>
 +
</html>
 +
<br><br><br>
 
[[File:0SdCardInterface.gif]]
 
[[File:0SdCardInterface.gif]]
 +
<br><br>
 +
 +
= Downloads=
 +
Download the complete project folder from the below link:
 +
https://codeload.github.com/ExploreEmbedded/Explore-Cortex-M3-LPC1768-Stick-DVB-14001/zip/master<br><br><br><br>
 +
 +
 +
 +
Have a opinion, suggestion , question or feedback about the article let it out here!
 +
{{DISQUS}}

Latest revision as of 15:29, 14 April 2016

Objective:

In this tutorial we will discuss how to interface SD CARD with lpc1768 to read and write the fat32 files.


References

The original SD card library for AVR controllers can be downloaded from http://www.dharmanitech.com/.
These libraries have been modified to provide the standard interfaces like File_Write/File_read and also supports multiple file access.
Check the below links for fat32 basics:
https://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html
http://www.tavi.co.uk/phobos/fat.html



Configuration

The number of files to be handled simultaneously can be configured in fat32.h using the constant C_MaxFilesOpening_U8.
To print the debug messages set FAT32_DEBUG_ENABLE to 1.


Limitations and Warning

The file name should max 11-chars including the file type.
There are chances of SD card getting corrupted if the libraries are not used properly.
Below are some tips to avoid the sd card corruption.

  1. Ensure the file is terminated with EOF before closing.
  2. Do not disconnect the SD card until the files are closed in software.
  3. While writing the data to file. Open the file, write the data and close it. Ensure these steps are followed in one go.



File Handling Functions

The below table shows the list of functions to access the sd card.
Refer fat32.c/fat32.h for more info.

Function Description
FILE_Open This functions opens the specified file in requested mode(READ/WRITE/APPEND).
FILE_Close This functions closes the file and releases the memory used by the file.
FILE_Delete This functions deletes the file from SD card.
FILE_GetCh This functions reads a byte of data from the file, Once the End of File is reached it returns EOF(26)
FILE_PutCh This functions writes a byte of data to the file, EOF(26) needs to be passed to mark the end of file and save it to SD card.
FILE_GetList This functions traverses through the SD card and lists the available files with their size.
FILE_GetMemoryStatics This functions calculates the total and free memory of the SD card. It takes upto 10secs(for 32GB) to calculate the memory statics depending on the size of CARD





Formatting SD Card

As this Sd Crad library is for fat32, the card needs to be formatted using fat32 settings as shown below.

Fat32Formatting.png

Connection Diagram

code

Below example shows the usage of all the fat32 functions.


0SdCardInterface.gif

Downloads

Download the complete project folder from the below link: https://codeload.github.com/ExploreEmbedded/Explore-Cortex-M3-LPC1768-Stick-DVB-14001/zip/master




Have a opinion, suggestion , question or feedback about the article let it out here!