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.

65 lines
1.4KB

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