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.

TestHardware.ino 2.1KB

9 年之前
9 年之前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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.createErasable("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. }