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.

123 rindas
3.5KB

  1. /*
  2. SD card test
  3. This example shows how use the utility libraries on which the'
  4. SD library is based in order to get info about your SD card.
  5. Very useful for testing a card when you're not sure whether its working or not.
  6. The circuit:
  7. * SD card attached to SPI bus as follows:
  8. ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila, pin 7 on Teensy with audio board
  9. ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
  10. ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila, pin 14 on Teensy with audio board
  11. ** CS - depends on your SD card shield or module - pin 10 on Teensy with audio board
  12. Pin 4 used here for consistency with other Arduino examples
  13. created 28 Mar 2011
  14. by Limor Fried
  15. modified 9 Apr 2012
  16. by Tom Igoe
  17. */
  18. // include the SD library:
  19. #include <SD.h>
  20. #include <SPI.h>
  21. // set up variables using the SD utility library functions:
  22. Sd2Card card;
  23. SdVolume volume;
  24. SdFile root;
  25. // change this to match your SD shield or module;
  26. // Arduino Ethernet shield: pin 4
  27. // Adafruit SD shields and modules: pin 10
  28. // Sparkfun SD shield: pin 8
  29. // Teensy audio board: pin 10
  30. // Wiz820+SD board: pin 4
  31. // Teensy 2.0: pin 0
  32. // Teensy++ 2.0: pin 20
  33. const int chipSelect = 4;
  34. void setup()
  35. {
  36. //UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
  37. //SPI.setMOSI(7); // Audio shield has MOSI on pin 7
  38. //SPI.setSCK(14); // Audio shield has SCK on pin 14
  39. // Open serial communications and wait for port to open:
  40. Serial.begin(9600);
  41. while (!Serial) {
  42. ; // wait for serial port to connect. Needed for Leonardo only
  43. }
  44. Serial.print("\nInitializing SD card...");
  45. // we'll use the initialization code from the utility libraries
  46. // since we're just testing if the card is working!
  47. if (!card.init(SPI_HALF_SPEED, chipSelect)) {
  48. Serial.println("initialization failed. Things to check:");
  49. Serial.println("* is a card inserted?");
  50. Serial.println("* is your wiring correct?");
  51. Serial.println("* did you change the chipSelect pin to match your shield or module?");
  52. return;
  53. } else {
  54. Serial.println("Wiring is correct and a card is present.");
  55. }
  56. // print the type of card
  57. Serial.print("\nCard type: ");
  58. switch(card.type()) {
  59. case SD_CARD_TYPE_SD1:
  60. Serial.println("SD1");
  61. break;
  62. case SD_CARD_TYPE_SD2:
  63. Serial.println("SD2");
  64. break;
  65. case SD_CARD_TYPE_SDHC:
  66. Serial.println("SDHC");
  67. break;
  68. default:
  69. Serial.println("Unknown");
  70. }
  71. // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  72. if (!volume.init(card)) {
  73. Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
  74. return;
  75. }
  76. // print the type and size of the first FAT-type volume
  77. uint32_t volumesize;
  78. Serial.print("\nVolume type is FAT");
  79. Serial.println(volume.fatType(), DEC);
  80. Serial.println();
  81. volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
  82. volumesize *= volume.clusterCount(); // we'll have a lot of clusters
  83. if (volumesize < 8388608ul) {
  84. Serial.print("Volume size (bytes): ");
  85. Serial.println(volumesize * 512); // SD card blocks are always 512 bytes
  86. }
  87. Serial.print("Volume size (Kbytes): ");
  88. volumesize /= 2;
  89. Serial.println(volumesize);
  90. Serial.print("Volume size (Mbytes): ");
  91. volumesize /= 1024;
  92. Serial.println(volumesize);
  93. Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  94. root.openRoot(volume);
  95. // list all files in the card with date and size
  96. root.ls(LS_R | LS_DATE | LS_SIZE);
  97. }
  98. void loop(void) {
  99. }