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.

48 lines
1.5KB

  1. // An example of an external chip select functions.
  2. // Useful for port expanders or replacement of the standard GPIO functions.
  3. //
  4. #include "SdFat.h"
  5. // SD_CHIP_SELECT_MODE must be set to one or two in SdFat/SdFatConfig.h.
  6. // A value of one allows optional replacement and two requires replacement.
  7. #if SD_CHIP_SELECT_MODE == 1 || SD_CHIP_SELECT_MODE == 2
  8. // SD chip select pin.
  9. #define SD_CS_PIN SS
  10. #define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(50))
  11. SdFat sd;
  12. // Stats to verify function calls.
  13. uint32_t initCalls = 0;
  14. uint32_t writeCalls = 0;
  15. //------------------------------------------------------------------------------
  16. // Modify these functions for your port expander or custom GPIO library.
  17. void sdCsInit(SdCsPin_t pin) {
  18. initCalls++;
  19. pinMode(pin, OUTPUT);
  20. }
  21. void sdCsWrite(SdCsPin_t pin, bool level) {
  22. writeCalls++;
  23. digitalWrite(pin, level);
  24. }
  25. //------------------------------------------------------------------------------
  26. void setup() {
  27. Serial.begin(9600);
  28. if (!sd.begin(SD_CONFIG)) {
  29. sd.initErrorHalt(&Serial);
  30. }
  31. sd.ls(&Serial, LS_SIZE);
  32. Serial.print(F("sdCsInit calls: "));
  33. Serial.println(initCalls);
  34. Serial.print(F("sdCsWrite calls: "));
  35. Serial.println(writeCalls);
  36. }
  37. //------------------------------------------------------------------------------
  38. void loop() {}
  39. #else // SD_CHIP_SELECT_MODE == 1 || SD_CHIP_SELECT_MODE == 2
  40. #error SD_CHIP_SELECT_MODE must be one or two in SdFat/SdFatConfig.h
  41. #endif // SD_CHIP_SELECT_MODE == 1 || SD_CHIP_SELECT_MODE == 2