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.

62 lines
1.4KB

  1. #include <SerialFlash.h>
  2. #include <SPI.h>
  3. const int FlashChipSelect = 6; // digital pin for flash chip CS pin
  4. //const int FlashChipSelect = 21; // Arduino 101 built-in SPI Flash
  5. void setup() {
  6. //uncomment these if using Teensy audio shield
  7. //SPI.setSCK(14); // Audio shield has SCK on pin 14
  8. //SPI.setMOSI(7); // Audio shield has MOSI on pin 7
  9. //uncomment these if you have other SPI chips connected
  10. //to keep them disabled while using only SerialFlash
  11. //pinMode(4, INPUT_PULLUP);
  12. //pinMode(10, INPUT_PULLUP);
  13. Serial.begin(9600);
  14. // wait for Arduino Serial Monitor
  15. while (!Serial) ;
  16. delay(100);
  17. Serial.println("All Files on SPI Flash chip:");
  18. if (!SerialFlash.begin(FlashChipSelect)) {
  19. error("Unable to access SPI Flash chip");
  20. }
  21. SerialFlash.opendir();
  22. while (1) {
  23. char filename[64];
  24. uint32_t filesize;
  25. if (SerialFlash.readdir(filename, sizeof(filename), filesize)) {
  26. Serial.print(" ");
  27. Serial.print(filename);
  28. spaces(20 - strlen(filename));
  29. Serial.print(" ");
  30. Serial.print(filesize);
  31. Serial.print(" bytes");
  32. Serial.println();
  33. } else {
  34. break; // no more files
  35. }
  36. }
  37. }
  38. void spaces(int num) {
  39. for (int i=0; i < num; i++) {
  40. Serial.print(" ");
  41. }
  42. }
  43. void loop() {
  44. }
  45. void error(const char *message) {
  46. while (1) {
  47. Serial.println(message);
  48. delay(2500);
  49. }
  50. }