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.

63 line
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. unsigned int count = 0;
  23. while (1) {
  24. char filename[64];
  25. unsigned long filesize;
  26. if (SerialFlash.readdir(filename, sizeof(filename), filesize)) {
  27. Serial.print(" ");
  28. Serial.print(filename);
  29. spaces(20 - strlen(filename));
  30. Serial.print(" ");
  31. Serial.print(filesize);
  32. Serial.print(" bytes");
  33. Serial.println();
  34. } else {
  35. break; // no more files
  36. }
  37. }
  38. }
  39. void spaces(int num) {
  40. for (int i=0; i < num; i++) {
  41. Serial.print(" ");
  42. }
  43. }
  44. void loop() {
  45. }
  46. void error(const char *message) {
  47. while (1) {
  48. Serial.println(message);
  49. delay(2500);
  50. }
  51. }