Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

265 linhas
9.8KB

  1. /* Arduino SdFat Library
  2. * Copyright (C) 2012 by William Greiman
  3. *
  4. * This file is part of the Arduino SdFat Library
  5. *
  6. * This Library is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This Library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Arduino SdFat Library. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. \mainpage Arduino %SdFat Library
  22. <CENTER>Copyright &copy; 2012, 2013, 2014 by William Greiman
  23. </CENTER>
  24. \section Intro Introduction
  25. The Arduino %SdFat Library is a minimal implementation of FAT16 and FAT32
  26. file systems on SD flash memory cards. Standard SD and high capacity SDHC
  27. cards are supported.
  28. Experimental support for FAT12 can be enabled by setting FAT12_SUPPORT
  29. nonzero in SdFatConfig.h.
  30. The %SdFat library only supports short 8.3 names.
  31. The main classes in %SdFat are SdFat, SdBaseFile, SdFile, File, StdioStream,
  32. \ref fstream, \ref ifstream, and \ref ofstream.
  33. The SdFat class maintains a FAT volume, a current working directory,
  34. and simplifies initialization of other classes.
  35. The SdBaseFile class provides basic file access functions such as open(),
  36. binary read(), binary write(), close(), remove(), and sync(). SdBaseFile
  37. is the smallest file class.
  38. The SdFile class has all the SdBaseFile class functions plus the Arduino
  39. Print class functions.
  40. The File class has all the SdBaseFile functions plus the functions in
  41. the Arduino SD.h File class. This provides compatibility with the
  42. Arduino SD.h library.
  43. The StdioStream class implements functions similar to Linux/Unix standard
  44. buffered input/output.
  45. The \ref fstream class implements C++ iostreams for both reading and writing
  46. text files.
  47. The \ref ifstream class implements C++ iostreams for reading text files.
  48. The \ref ofstream class implements C++ iostreams for writing text files.
  49. The classes \ref ibufstream and \ref obufstream format and parse character
  50. strings in memory buffers.
  51. the classes ArduinoInStream and ArduinoOutStream provide iostream functions
  52. for Serial, LiquidCrystal, and other devices.
  53. A number of example are provided in the %SdFat/examples folder. These were
  54. developed to test %SdFat and illustrate its use.
  55. \section Install Installation
  56. You must manually install SdFat by copying the SdFat folder from the download
  57. package to the Arduino libraries folder in you sketch book.
  58. See the Manual installation section of this guide.
  59. http://arduino.cc/en/Guide/Libraries
  60. \section SDconfig SdFat Configuration
  61. Several configuration options may be changed by editing the SdFatConfig.h
  62. file in the SdFat folder.
  63. Set SD_FILE_USES_STREAM nonzero to use Stream instead of Print for SdFile.
  64. Using Stream will use more flash.
  65. To enable SD card CRC checking set USE_SD_CRC nonzero.
  66. To use multiple SD cards set USE_MULTIPLE_CARDS nonzero.
  67. Set FAT12_SUPPORT nonzero to enable use of FAT12 volumes.
  68. FAT12 has not been well tested and requires additional flash.
  69. Set USE_ARDUINO_SPI_LIBRARY nonzero to force use of Arduino Standard
  70. SPI library. This will override native and software SPI for all boards.
  71. Use of software SPI can be enabled for selected boards by setting the symbols
  72. AVR_SOFT_SPI, DUE_SOFT_SPI, LEONARDO_SOFT_SPI, MEGA_SOFT_SPI,
  73. and TEENSY3_SOFT_SPI.
  74. Set ENABLE_SPI_TRANSACTION nonzero to enable the SPI transaction feature
  75. of the standard Arduino SPI library. You must include SPI.h in your
  76. sketches when ENABLE_SPI_TRANSACTION is nonzero.
  77. Set ENABLE_SPI_YIELD nonzero to enable release of the SPI bus during
  78. SD card busy waits.
  79. \section SDcard SD\SDHC Cards
  80. Arduinos access SD cards using the cards SPI protocol. PCs, Macs, and
  81. most consumer devices use the 4-bit parallel SD protocol. A card that
  82. functions well on A PC or Mac may not work well on the Arduino.
  83. Most cards have good SPI read performance but cards vary widely in SPI
  84. write performance. Write performance is limited by how efficiently the
  85. card manages internal erase/remapping operations. The Arduino cannot
  86. optimize writes to reduce erase operations because of its limit RAM.
  87. SanDisk cards generally have good write performance. They seem to have
  88. more internal RAM buffering than other cards and therefore can limit
  89. the number of flash erase operations that the Arduino forces due to its
  90. limited RAM.
  91. \section Hardware Hardware Configuration
  92. %SdFat was developed using an
  93. <A HREF = "http://www.adafruit.com/"> Adafruit Industries</A>
  94. Data Logging Shield.
  95. The hardware interface to the SD card should not use a resistor based level
  96. shifter. %SdFat sets the SPI bus frequency to 8 MHz which results in signal
  97. rise times that are too slow for the edge detectors in many newer SD card
  98. controllers when resistor voltage dividers are used.
  99. The 5 to 3.3 V level shifter for 5 V Arduinos should be IC based like the
  100. 74HC4050N based circuit shown in the file SdLevel.png. The Adafruit Wave Shield
  101. uses a 74AHC125N. Gravitech sells SD and MicroSD Card Adapters based on the
  102. 74LCX245.
  103. If you are using a resistor based level shifter and are having problems try
  104. setting the SPI bus frequency to 4 MHz. This can be done by using
  105. card.init(SPI_HALF_SPEED) to initialize the SD card.
  106. \section comment Bugs and Comments
  107. If you wish to report bugs or have comments, send email to fat16lib@sbcglobal.net.
  108. \section SdFatClass SdFat Usage
  109. %SdFat uses a slightly restricted form of short names.
  110. Short names are limited to 8 characters followed by an optional period (.)
  111. and extension of up to 3 characters. The characters may be any combination
  112. of letters and digits. The following special characters are also allowed:
  113. $ % ' - _ @ ~ ` ! ( ) { } ^ # &
  114. Short names are always converted to upper case and their original case
  115. value is lost.
  116. An application which writes to a file using print(), println() or
  117. \link SdFile::write write() \endlink must call \link SdFile::sync() sync() \endlink
  118. at the appropriate time to force data and directory information to be written
  119. to the SD Card. Data and directory information are also written to the SD card
  120. when \link SdFile::close() close() \endlink is called.
  121. Applications must use care calling \link SdFile::sync() sync() \endlink
  122. since 2048 bytes of I/O is required to update file and
  123. directory information. This includes writing the current data block, reading
  124. the block that contains the directory entry for update, writing the directory
  125. block back and reading back the current data block.
  126. It is possible to open a file with two or more instances of a file object.
  127. A file may be corrupted if data is written to the file by more than one
  128. instance of a file object.
  129. \section HowTo How to format SD Cards as FAT Volumes
  130. The best way to restore an SD card's format on a PC or Mac is to use
  131. SDFormatter which can be downloaded from:
  132. http://www.sdcard.org/downloads
  133. A formatter sketch, SdFormatter.ino, is included in the
  134. %SdFat/examples/SdFormatter directory. This sketch attempts to
  135. emulate SD Association's SDFormatter.
  136. SDFormatter aligns flash erase boundaries with file
  137. system structures which reduces write latency and file system overhead.
  138. The PC/Mac SDFormatter does not have an option for FAT type so it may format
  139. very small cards as FAT12. Use the SdFat formatter to force FAT16
  140. formatting of small cards.
  141. Do not format the SD card with an OS utility, OS utilities do not format SD
  142. cards in conformance with the SD standard.
  143. You should use a freshly formatted SD card for best performance. FAT
  144. file systems become slower if many files have been created and deleted.
  145. This is because the directory entry for a deleted file is marked as deleted,
  146. but is not deleted. When a new file is created, these entries must be scanned
  147. before creating the file. Also files can become
  148. fragmented which causes reads and writes to be slower.
  149. \section ExampleFilder Examples
  150. A number of examples are provided in the SdFat/examples folder.
  151. See the html documentation for a list.
  152. To access these examples from the Arduino development environment
  153. go to: %File -> Examples -> %SdFat -> \<Sketch Name\>
  154. Compile, upload to your Arduino and click on Serial Monitor to run
  155. the example.
  156. Here is a list:
  157. AnalogBinLogger - Fast AVR ADC logger - see the AnalogBinLoggerExtras folder.
  158. bench - A read/write benchmark.
  159. cin_cout - Demo of ArduinoInStream and ArduinoOutStream.
  160. dataLogger - A simple modifiable data logger.
  161. directoryFunctions - Demo of chdir(), ls(), mkdir(), and rmdir().
  162. fgets - Demo of the fgets read line/string function.
  163. formating - Print a table with various formatting options.
  164. getline - Example of getline from section 27.7.1.3 of the C++ standard.
  165. LowLatencyLogger - A modifiable data logger for higher data rates.
  166. OpenNext - Open all files in the root dir and print their filename.
  167. PrintBenchmark - A simple benchmark for printing to a text file.
  168. QuickStart - A sketch to quickly test your SD card and SD shield/module.
  169. RawWrite - A test of raw write functions for contiguous files.
  170. readCSV - Read a comma-separated value file using iostream extractors.
  171. ReadWriteSdFat - SdFat version of Arduino SD ReadWrite example.
  172. rename - A demo of SdFat::rename(old, new) and SdFile::rename(dirFile, newPath).
  173. SdFormatter - This sketch will format an SD or SDHC card.
  174. SdInfo - Initialize an SD card and analyze its structure for trouble shooting.
  175. StdioBench - Demo and test of stdio style stream.
  176. StreamParseInt - Simple demo of parseInt() Stream member function.
  177. StressTest - Create and write files until the SD is full.
  178. Timestamp - Sets file create, modify, and access timestamps.
  179. TwoCards - Example using two SD cards.
  180. */