Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

119 rindas
13KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.6"/>
  7. <title>SdFat: Arduino SdFat Library</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <script type="text/javascript" src="jquery.js"></script>
  10. <script type="text/javascript" src="dynsections.js"></script>
  11. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  12. </head>
  13. <body>
  14. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  15. <div id="titlearea">
  16. <table cellspacing="0" cellpadding="0">
  17. <tbody>
  18. <tr style="height: 56px;">
  19. <td style="padding-left: 0.5em;">
  20. <div id="projectname">SdFat
  21. </div>
  22. </td>
  23. </tr>
  24. </tbody>
  25. </table>
  26. </div>
  27. <!-- end header part -->
  28. <!-- Generated by Doxygen 1.8.6 -->
  29. <div id="navrow1" class="tabs">
  30. <ul class="tablist">
  31. <li class="current"><a href="index.html"><span>Main&#160;Page</span></a></li>
  32. <li><a href="namespaces.html"><span>Namespaces</span></a></li>
  33. <li><a href="annotated.html"><span>Classes</span></a></li>
  34. <li><a href="files.html"><span>Files</span></a></li>
  35. </ul>
  36. </div>
  37. </div><!-- top -->
  38. <div class="header">
  39. <div class="headertitle">
  40. <div class="title">Arduino SdFat Library </div> </div>
  41. </div><!--header-->
  42. <div class="contents">
  43. <div class="textblock"><center>Copyright &copy; 2012, 2013, 2014 by William Greiman </center><h1><a class="anchor" id="Intro"></a>
  44. Introduction</h1>
  45. <p>The Arduino SdFat Library is a minimal implementation of FAT16 and FAT32 file systems on SD flash memory cards. Standard SD and high capacity SDHC cards are supported.</p>
  46. <p>Experimental support for FAT12 can be enabled by setting FAT12_SUPPORT nonzero in <a class="el" href="_sd_fat_config_8h.html" title="configuration definitions ">SdFatConfig.h</a>.</p>
  47. <p>The SdFat library only supports short 8.3 names.</p>
  48. <p>The main classes in SdFat are <a class="el" href="class_sd_fat.html" title="Integration class for the SdFat library. ">SdFat</a>, <a class="el" href="class_sd_file.html" title="SdBaseFile with Arduino Stream. ">SdFile</a>, <a class="el" href="class_stdio_stream.html" title="StdioStream implements a minimal stdio stream. ">StdioStream</a>, <a class="el" href="classfstream.html">fstream</a>, <a class="el" href="classifstream.html">ifstream</a>, and <a class="el" href="classofstream.html">ofstream</a>.</p>
  49. <p>The <a class="el" href="class_sd_fat.html" title="Integration class for the SdFat library. ">SdFat</a> class maintains a volume working directories, a current working directory, and simplifies initialization of other classes.</p>
  50. <p>The <a class="el" href="class_sd_file.html" title="SdBaseFile with Arduino Stream. ">SdFile</a> class provides binary file access functions such as open(), read(), remove(), write(), close() and sync(). This class supports access to the root directory and subdirectories.</p>
  51. <p>The <a class="el" href="class_stdio_stream.html" title="StdioStream implements a minimal stdio stream. ">StdioStream</a> class implements functions similar to Linux/Unix standard buffered input/output.</p>
  52. <p>The <a class="el" href="classfstream.html">fstream</a> class implements C++ iostreams for both reading and writing text files.</p>
  53. <p>The <a class="el" href="classifstream.html">ifstream</a> class implements the C++ iostreams for reading text files.</p>
  54. <p>The <a class="el" href="classofstream.html">ofstream</a> class implements the C++ iostreams for writing text files.</p>
  55. <p>The classes <a class="el" href="classibufstream.html">ibufstream</a> and <a class="el" href="classobufstream.html">obufstream</a> format and parse character strings in memory buffers.</p>
  56. <p>the classes <a class="el" href="class_arduino_in_stream.html" title="Input stream for Arduino Stream objects. ">ArduinoInStream</a> and <a class="el" href="class_arduino_out_stream.html" title="Output stream for Arduino Print objects. ">ArduinoOutStream</a> provide iostream functions for Serial, LiquidCrystal, and other devices.</p>
  57. <p>The <a class="el" href="class_sd_volume.html" title="Access FAT16 and FAT32 volumes on SD and SDHC cards. ">SdVolume</a> class supports FAT16 and FAT32 partitions. Most applications will not need to call <a class="el" href="class_sd_volume.html" title="Access FAT16 and FAT32 volumes on SD and SDHC cards. ">SdVolume</a> member function.</p>
  58. <p>The <a class="el" href="class_sd2_card.html" title="Raw access to SD and SDHC flash memory cards. ">Sd2Card</a> class supports access to standard SD cards and SDHC cards. Most applications will not need to call <a class="el" href="class_sd2_card.html" title="Raw access to SD and SDHC flash memory cards. ">Sd2Card</a> functions. The <a class="el" href="class_sd2_card.html" title="Raw access to SD and SDHC flash memory cards. ">Sd2Card</a> class can be used for raw access to the SD card.</p>
  59. <p>A number of example are provided in the SdFat/examples folder. These were developed to test SdFat and illustrate its use.</p>
  60. <p>SdFat was developed for high speed data recording. SdFat was used to implement an audio record/play class, WaveRP, for the Adafruit Wave Shield. This application uses special <a class="el" href="class_sd2_card.html" title="Raw access to SD and SDHC flash memory cards. ">Sd2Card</a> calls to write to contiguous files in raw mode. These functions reduce write latency so that audio can be recorded with the small amount of RAM in the Arduino.</p>
  61. <h1><a class="anchor" id="SDcard"></a>
  62. SD\SDHC Cards</h1>
  63. <p>Arduinos access SD cards using the cards SPI protocol. PCs, Macs, and most consumer devices use the 4-bit parallel SD protocol. A card that functions well on A PC or Mac may not work well on the Arduino.</p>
  64. <p>Most cards have good SPI read performance but cards vary widely in SPI write performance. Write performance is limited by how efficiently the card manages internal erase/remapping operations. The Arduino cannot optimize writes to reduce erase operations because of its limit RAM.</p>
  65. <p>SanDisk cards generally have good write performance. They seem to have more internal RAM buffering than other cards and therefore can limit the number of flash erase operations that the Arduino forces due to its limited RAM.</p>
  66. <h1><a class="anchor" id="Hardware"></a>
  67. Hardware Configuration</h1>
  68. <p>SdFat was developed using an <a href="http://www.adafruit.com/">Adafruit Industries</a> Data Logging Shield.</p>
  69. <p>The hardware interface to the SD card should not use a resistor based level shifter. SdFat sets the SPI bus frequency to 8 MHz which results in signal rise times that are too slow for the edge detectors in many newer SD card controllers when resistor voltage dividers are used.</p>
  70. <p>The 5 to 3.3 V level shifter for 5 V Arduinos should be IC based like the 74HC4050N based circuit shown in the file SdLevel.png. The Adafruit Wave Shield uses a 74AHC125N. Gravitech sells SD and MicroSD Card Adapters based on the 74LCX245.</p>
  71. <p>If you are using a resistor based level shifter and are having problems try setting the SPI bus frequency to 4 MHz. This can be done by using card.init(SPI_HALF_SPEED) to initialize the SD card.</p>
  72. <h1><a class="anchor" id="comment"></a>
  73. Bugs and Comments</h1>
  74. <p>If you wish to report bugs or have comments, send email to <a href="#" onclick="location.href='mai'+'lto:'+'fat'+'16'+'lib'+'@s'+'bcg'+'lo'+'bal'+'.n'+'et'; return false;">fat16<span style="display: none;">.nosp@m.</span>lib@<span style="display: none;">.nosp@m.</span>sbcgl<span style="display: none;">.nosp@m.</span>obal<span style="display: none;">.nosp@m.</span>.net</a>.</p>
  75. <h1><a class="anchor" id="SdFatClass"></a>
  76. SdFat Usage</h1>
  77. <p>SdFat uses a slightly restricted form of short names. Only printable ASCII characters are supported. No characters with code point values greater than 127 are allowed. Space is not allowed even though space was allowed in the API of early versions of DOS.</p>
  78. <p>Short names are limited to 8 characters followed by an optional period (.) and extension of up to 3 characters. The characters may be any combination of letters and digits. The following special characters are also allowed:</p>
  79. <p>$ % ' - _ @ ~ ` ! ( ) { } ^ # &amp;</p>
  80. <p>Short names are always converted to upper case and their original case value is lost.</p>
  81. <dl class="section user"><dt></dt><dd>An application which writes to a file using print(), println() or <a class="el" href="class_sd_file.html#a67267a4b63d03a16e099195935613006">write() </a> must call <a class="el" href="class_sd_base_file.html#a292247972772be832f2c6ea166f4049a">sync() </a> at the appropriate time to force data and directory information to be written to the SD Card. Data and directory information are also written to the SD card when <a class="el" href="class_sd_base_file.html#a17f7e949aa0f80d89782d8e31f5edc15">close() </a> is called.</dd></dl>
  82. <dl class="section user"><dt></dt><dd>Applications must use care calling <a class="el" href="class_sd_base_file.html#a292247972772be832f2c6ea166f4049a">sync() </a> since 2048 bytes of I/O is required to update file and directory information. This includes writing the current data block, reading the block that contains the directory entry for update, writing the directory block back and reading back the current data block.</dd></dl>
  83. <p>It is possible to open a file with two or more instances of <a class="el" href="class_sd_file.html" title="SdBaseFile with Arduino Stream. ">SdFile</a>. A file may be corrupted if data is written to the file by more than one instance of <a class="el" href="class_sd_file.html" title="SdBaseFile with Arduino Stream. ">SdFile</a>.</p>
  84. <h1><a class="anchor" id="HowTo"></a>
  85. How to format SD Cards as FAT Volumes</h1>
  86. <p>You should use a freshly formatted SD card for best performance. FAT file systems become slower if many files have been created and deleted. This is because the directory entry for a deleted file is marked as deleted, but is not deleted. When a new file is created, these entries must be scanned before creating the file, a flaw in the FAT design. Also files can become fragmented which causes reads and writes to be slower.</p>
  87. <p>A formatter sketch, SdFormatter.pde, is included in the SdFat/examples/SdFormatter directory. This sketch attempts to emulate SD Association's SDFormatter.</p>
  88. <p>The best way to restore an SD card's format on a PC is to use SDFormatter which can be downloaded from:</p>
  89. <p><a href="http://www.sdcard.org/consumers/formatter/">http://www.sdcard.org/consumers/formatter/</a></p>
  90. <p>SDFormatter aligns flash erase boundaries with file system structures which reduces write latency and file system overhead.</p>
  91. <p>SDFormatter does not have an option for FAT type so it may format small cards as FAT12.</p>
  92. <p>After the MBR is restored by SDFormatter you may need to reformat small cards that have been formatted FAT12 to force the volume type to be FAT16.</p>
  93. <p>If you reformat the SD card with an OS utility, choose a cluster size that will result in:</p>
  94. <p>4084 &lt; CountOfClusters &amp;&amp; CountOfClusters &lt; 65525</p>
  95. <p>The volume will then be FAT16.</p>
  96. <p>If you are formatting an SD card on OS X or Linux, be sure to use the first partition. Format this partition with a cluster count in above range for FAT16. SDHC cards should be formatted FAT32 with a cluster size of 32 KB.</p>
  97. <p>Microsoft operating systems support removable media formatted with a Master Boot Record, MBR, or formatted as a super floppy with a FAT Boot Sector in block zero.</p>
  98. <p>Microsoft operating systems expect MBR formatted removable media to have only one partition. The first partition should be used.</p>
  99. <p>Microsoft operating systems do not support partitioning SD flash cards. If you erase an SD card with a program like KillDisk, Most versions of Windows will format the card as a super floppy.</p>
  100. <h1><a class="anchor" id="References"></a>
  101. References</h1>
  102. <p>The Arduino site:</p>
  103. <p><a href="http://www.arduino.cc/">http://www.arduino.cc/</a></p>
  104. <p>For more information about FAT file systems see:</p>
  105. <p><a href="http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx">http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx</a></p>
  106. <p>For information about using SD cards as SPI devices see:</p>
  107. <p><a href="http://www.sdcard.org/developers/tech/sdcard/pls/Simplified_Physical_Layer_Spec.pdf">http://www.sdcard.org/developers/tech/sdcard/pls/Simplified_Physical_Layer_Spec.pdf</a></p>
  108. <p>The ATmega328 datasheet:</p>
  109. <p><a href="http://www.atmel.com/dyn/resources/prod_documents/doc8161.pdf">http://www.atmel.com/dyn/resources/prod_documents/doc8161.pdf</a> </p>
  110. </div></div><!-- contents -->
  111. <!-- start footer part -->
  112. <hr class="footer"/><address class="footer"><small>
  113. Generated on Fri Oct 24 2014 05:45:13 for SdFat by &#160;<a href="http://www.doxygen.org/index.html">
  114. <img class="footer" src="doxygen.png" alt="doxygen"/>
  115. </a> 1.8.6
  116. </small></address>
  117. </body>
  118. </html>