Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

97 linhas
2.1KB

  1. #include <SerialFlash.h>
  2. #include <SPI.h>
  3. SerialFlashFile file;
  4. void setup() {
  5. char filename[40];
  6. uint32_t len;
  7. while (!Serial) ;
  8. delay(10);
  9. SPI.setSCK(14); // Audio shield has SCK on pin 14
  10. SPI.setMOSI(7); // Audio shield has MOSI on pin 7
  11. Serial.println("Test Hardware");
  12. SerialFlash.begin();
  13. #if 0
  14. Serial.println("erase");
  15. SerialFlash.eraseAll();
  16. while (!SerialFlash.ready()) {
  17. }
  18. Serial.println("erase done");
  19. #endif
  20. Serial.println("Directory:");
  21. while (SerialFlash.readdir(filename, sizeof(filename), len)) {
  22. Serial.print(" file: ");
  23. Serial.print(filename);
  24. Serial.print(" bytes: ");
  25. Serial.print(len);
  26. Serial.println();
  27. }
  28. Serial.println();
  29. Serial.println("simple.txt test");
  30. file = SerialFlash.open("simple.txt");
  31. if (file) {
  32. Serial.println(" file opened");
  33. Serial.print(" length = ");
  34. Serial.println(file.size());
  35. Serial.print(" addr on chip = ");
  36. Serial.println(file.getFlashAddress());
  37. file.close();
  38. } else {
  39. Serial.println(" create file");
  40. SerialFlash.create("simple.txt", 516);
  41. }
  42. Serial.println("soundfile.wav test");
  43. file = SerialFlash.open("soundfile.wav");
  44. if (file) {
  45. Serial.println(" file opened");
  46. Serial.print(" length = ");
  47. Serial.println(file.size());
  48. Serial.print(" addr on chip = ");
  49. Serial.println(file.getFlashAddress());
  50. file.close();
  51. } else {
  52. Serial.println(" create file");
  53. SerialFlash.createWritable("soundfile.wav", 3081000);
  54. }
  55. Serial.println("wavetable1 test");
  56. file = SerialFlash.open("wavetable1");
  57. if (file) {
  58. Serial.println(" file opened");
  59. Serial.print(" length = ");
  60. Serial.println(file.size());
  61. Serial.print(" addr on chip = ");
  62. Serial.println(file.getFlashAddress());
  63. file.close();
  64. } else {
  65. Serial.println(" create file");
  66. SerialFlash.create("wavetable1", 181003);
  67. }
  68. Serial.println("end");
  69. }
  70. void loop() {
  71. }
  72. void printbuf(const void *buf, uint32_t len)
  73. {
  74. const uint8_t *p = (const uint8_t *)buf;
  75. do {
  76. Serial.print(*p++);
  77. Serial.print(" ");
  78. } while (--len > 0);
  79. Serial.println();
  80. }