Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

9 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <SerialFlash.h>
  2. #include <SD.h>
  3. #include <SPI.h>
  4. const int SDchipSelect = 4;
  5. const int FlashChipSelect = 6;
  6. void setup() {
  7. //uncomment these if using Teensy audio shield
  8. SPI.setSCK(14); // Audio shield has SCK on pin 14
  9. SPI.setMOSI(7); // Audio shield has MOSI on pin 7
  10. // wait up to 10 seconds for Arduino Serial Monitor
  11. unsigned long startMillis = millis();
  12. while (!Serial && (millis() - startMillis < 10000)) ;
  13. delay(100);
  14. Serial.println("Copy all files from SD Card to SPI Flash");
  15. if (!SD.begin(SDchipSelect)) {
  16. error("Unable to access SD card");
  17. }
  18. if (!SerialFlash.begin()) {
  19. error("Unable to access SPI Flash chip");
  20. }
  21. int count = 0;
  22. File rootdir = SD.open("/");
  23. while (1) {
  24. Serial.println();
  25. File f = rootdir.openNextFile();
  26. if (!f) break;
  27. const char *filename = f.name();
  28. Serial.print(filename);
  29. Serial.print(" ");
  30. unsigned long length = f.size();
  31. Serial.println(length);
  32. if (SerialFlash.create(filename, length)) {
  33. SerialFlashFile ff = SerialFlash.open(filename);
  34. if (ff) {
  35. Serial.print(" copying");
  36. // copy data.
  37. unsigned long count = 0;
  38. while (count < length) {
  39. char buf[256];
  40. unsigned int n;
  41. n = f.read(buf, 256);
  42. ff.write(buf, n);
  43. count = count + n;
  44. Serial.print(".");
  45. }
  46. ff.close();
  47. Serial.println();
  48. } else {
  49. Serial.println(" error opening freshly created file!");
  50. }
  51. } else {
  52. Serial.println(" unable to create file");
  53. }
  54. if (++count > 12) break; // testing, only do first 12 files
  55. f.close();
  56. }
  57. rootdir.close();
  58. }
  59. void loop() {
  60. }
  61. void error(const char *message) {
  62. while (1) {
  63. Serial.println(message);
  64. delay(2500);
  65. }
  66. }