UserChipSelectFunction.ino 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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