Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ReadBenchmark.ino 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. while (1) {
  20. Serial.println("Unable to access SPI Flash chip");
  21. delay(2500);
  22. }
  23. }
  24. SerialFlash.opendir();
  25. int filecount = 0;
  26. while (1) {
  27. char filename[64];
  28. uint32_t filesize;
  29. if (SerialFlash.readdir(filename, sizeof(filename), filesize)) {
  30. Serial.print(" ");
  31. Serial.print(filename);
  32. Serial.print(", ");
  33. Serial.print(filesize);
  34. Serial.print(" bytes");
  35. SerialFlashFile file = SerialFlash.open(filename);
  36. if (file) {
  37. unsigned long usbegin = micros();
  38. unsigned long n = filesize;
  39. char buffer[256];
  40. while (n > 0) {
  41. unsigned long rd = n;
  42. if (rd > sizeof(buffer)) rd = sizeof(buffer);
  43. file.read(buffer, rd);
  44. n = n - rd;
  45. }
  46. unsigned long usend = micros();
  47. Serial.print(", read in ");
  48. Serial.print(usend - usbegin);
  49. Serial.print(" us, speed = ");
  50. Serial.print((float)filesize * 1000.0 / (float)(usend - usbegin));
  51. Serial.println(" kbytes/sec");
  52. file.close();
  53. } else {
  54. Serial.println(" error reading this file!");
  55. }
  56. filecount = filecount + 1;
  57. } else {
  58. if (filecount == 0) {
  59. Serial.println("No files found in SerialFlash memory.");
  60. }
  61. break; // no more files
  62. }
  63. }
  64. }
  65. void loop() {
  66. }