Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

77 lines
2.0KB

  1. // An example of the SoftSpiDriver template class.
  2. // This example is for an old Adafruit Data Logging Shield on a Mega.
  3. // Software SPI is required on Mega since this shield connects to pins 10-13.
  4. // This example will also run on an Uno and other boards using software SPI.
  5. //
  6. #include <SPI.h>
  7. #include "SdFat.h"
  8. #if SPI_DRIVER_SELECT == 2 // Must be set in SdFat/SdFatConfig.h
  9. // SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
  10. // 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
  11. #define SD_FAT_TYPE 0
  12. //
  13. // Chip select may be constant or RAM variable.
  14. const uint8_t SD_CS_PIN = 10;
  15. //
  16. // Pin numbers in templates must be constants.
  17. const uint8_t SOFT_MISO_PIN = 12;
  18. const uint8_t SOFT_MOSI_PIN = 11;
  19. const uint8_t SOFT_SCK_PIN = 13;
  20. // SdFat software SPI template
  21. SoftSpiDriver<SOFT_MISO_PIN, SOFT_MOSI_PIN, SOFT_SCK_PIN> softSpi;
  22. // Speed argument is ignored for software SPI.
  23. #define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(0), &softSpi)
  24. #if SD_FAT_TYPE == 0
  25. SdFat sd;
  26. File file;
  27. #elif SD_FAT_TYPE == 1
  28. SdFat32 sd;
  29. File32 file;
  30. #elif SD_FAT_TYPE == 2
  31. SdExFat sd;
  32. ExFile file;
  33. #elif SD_FAT_TYPE == 3
  34. SdFs sd;
  35. FsFile file;
  36. #else // SD_FAT_TYPE
  37. #error Invalid SD_FAT_TYPE
  38. #endif // SD_FAT_TYPE
  39. void setup() {
  40. Serial.begin(9600);
  41. // Wait for USB Serial
  42. while (!Serial) {
  43. SysCall::yield();
  44. }
  45. Serial.println("Type any character to start");
  46. while (!Serial.available()) {
  47. SysCall::yield();
  48. }
  49. if (!sd.begin(SD_CONFIG)) {
  50. sd.initErrorHalt();
  51. }
  52. if (!file.open("SoftSPI.txt", O_RDWR | O_CREAT)) {
  53. sd.errorHalt(F("open failed"));
  54. }
  55. file.println(F("This line was printed using software SPI."));
  56. file.rewind();
  57. while (file.available()) {
  58. Serial.write(file.read());
  59. }
  60. file.close();
  61. Serial.println(F("Done."));
  62. }
  63. //------------------------------------------------------------------------------
  64. void loop() {}
  65. #else // SPI_DRIVER_SELECT
  66. #error SPI_DRIVER_SELECT must be two in SdFat/SdFatConfig.h
  67. #endif //SPI_DRIVER_SELECT