Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

58 lines
1.5KB

  1. // An example of the SdFatSoftSpi template class.
  2. // This example is for an 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 ENABLE_SOFTWARE_SPI_CLASS // Must be set in SdFat/SdFatConfig.h
  9. //
  10. // Pin numbers in templates must be constants.
  11. const uint8_t SOFT_MISO_PIN = 12;
  12. const uint8_t SOFT_MOSI_PIN = 11;
  13. const uint8_t SOFT_SCK_PIN = 13;
  14. //
  15. // Chip select may be constant or RAM variable.
  16. const uint8_t SD_CHIP_SELECT_PIN = 10;
  17. // SdFat software SPI template
  18. SdFatSoftSpi<SOFT_MISO_PIN, SOFT_MOSI_PIN, SOFT_SCK_PIN> sd;
  19. // Test file.
  20. SdFile file;
  21. void setup() {
  22. Serial.begin(9600);
  23. // Wait for USB Serial
  24. while (!Serial) {
  25. SysCall::yield();
  26. }
  27. Serial.println("Type any character to start");
  28. while (!Serial.available()) {
  29. SysCall::yield();
  30. }
  31. if (!sd.begin(SD_CHIP_SELECT_PIN)) {
  32. sd.initErrorHalt();
  33. }
  34. if (!file.open("SoftSPI.txt", O_CREAT | O_RDWR)) {
  35. sd.errorHalt(F("open failed"));
  36. }
  37. file.println(F("This line was printed using software SPI."));
  38. file.rewind();
  39. while (file.available()) {
  40. Serial.write(file.read());
  41. }
  42. file.close();
  43. Serial.println(F("Done."));
  44. }
  45. //------------------------------------------------------------------------------
  46. void loop() {}
  47. #else // ENABLE_SOFTWARE_SPI_CLASS
  48. #error ENABLE_SOFTWARE_SPI_CLASS must be set non-zero in SdFat/SdFatConfig.h
  49. #endif //ENABLE_SOFTWARE_SPI_CLASS