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.

SoftwareSpi.ino 1.6KB

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