You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 5 година
пре 10 година
пре 8 година
пре 5 година
пре 10 година
пре 5 година
пре 10 година
пре 5 година
пре 10 година
пре 10 година
пре 8 година
пре 10 година
пре 5 година
пре 10 година
пре 5 година
пре 10 година
пре 10 година
пре 9 година
пре 10 година
пре 10 година
пре 10 година
пре 5 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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