Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Sistemi integrati - errore lettura microsd
Forum - Sistemi integrati - errore lettura microsd

Pagine: [ 1 2 ] Precedente | Prossimo
Avatar
alex1995 (Normal User)
Expert


Messaggi: 294
Iscritto: 27/01/2011

Segnala al moderatore
Postato alle 20:09
Lunedì, 05/01/2015
buona sera, ho un arduino mega 2560 r3 con l' ethernet shield che ha lo slot per la microsd, solo che non riesco a leggere o scrivere i file.l' ho formattata in fat32 con sdformatter, può essere che non sia compatibile con l' spi?

questo è il mio codice:

Codice sorgente - presumibilmente C++

  1. #include <SPI.h>
  2. #include <SD.h>
  3.  
  4. void setup()
  5. {
  6.   Serial.begin(9600);
  7.   pinMode(53, OUTPUT);
  8.   SD.begin();
  9.   SD.begin(53);
  10. }
  11.  
  12. void loop()
  13. {
  14.   File scriviFile  = SD.open("file.txt", FILE_WRITE);
  15.   if(scriviFile)
  16.   {
  17.     scriviFile.println("test");
  18.     scriviFile.close();
  19.     Serial.write("ok");
  20.   }
  21.   else
  22.   {
  23.     Serial.write("errore");
  24.   }
  25. }


PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 23:00
Lunedì, 05/01/2015
Se provi a flashare l'esempio Arduino_SD/CardInfo, cosa succede?

Codice sorgente - presumibilmente VB.NET

  1. /*
  2.   SD card test
  3.    
  4.  This example shows how use the utility libraries on which the'
  5.  SD library is based in order to get info about your SD card.
  6.  Very useful for testing a card when you're not sure whether its working or not.
  7.        
  8.  The circuit:
  9.   * SD card attached to SPI bus as follows:
  10.  ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila
  11.  ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila
  12.  ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila
  13.  ** CS - depends on your SD card shield or module.
  14.                 Pin 4 used here for consistency with other Arduino examples
  15.  
  16.  
  17.  created  28 Mar 2011
  18.  by Limor Fried
  19.  modified 9 Apr 2012
  20.  by Tom Igoe
  21.  */
  22.  // include the SD library:
  23. #include <SD.h>
  24.  
  25. // set up variables using the SD utility library functions:
  26. Sd2Card card;
  27. SdVolume volume;
  28. SdFile root;
  29.  
  30. // change this to match your SD shield or module;
  31. // Arduino Ethernet shield: pin 4
  32. // Adafruit SD shields and modules: pin 10
  33. // Sparkfun SD shield: pin 8
  34. const int chipSelect = 4;    
  35.  
  36. void setup()
  37. {
  38.  // Open serial communications and wait for port to open:
  39.   Serial.begin(9600);
  40.    while (!Serial) {
  41.     ; // wait for serial port to connect. Needed for Leonardo only
  42.   }
  43.  
  44.  
  45.   Serial.print("\nInitializing SD card...");
  46.   // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  47.   // Note that even if it's not used as the CS pin, the hardware SS pin
  48.   // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  49.   // or the SD library functions will not work.
  50.   pinMode(10, OUTPUT);     // change this to 53 on a mega
  51.  
  52.  
  53.   // we'll use the initialization code from the utility libraries
  54.   // since we're just testing if the card is working!
  55.   if (!card.init(SPI_HALF_SPEED, chipSelect)) {
  56.     Serial.println("initialization failed. Things to check:");
  57.     Serial.println("* is a card is inserted?");
  58.     Serial.println("* Is your wiring correct?");
  59.     Serial.println("* did you change the chipSelect pin to match your shield or module?");
  60.     return;
  61.   } else {
  62.    Serial.println("Wiring is correct and a card is present.");
  63.   }
  64.  
  65.   // print the type of card
  66.   Serial.print("\nCard type: ");
  67.   switch(card.type()) {
  68.     case SD_CARD_TYPE_SD1:
  69.       Serial.println("SD1");
  70.       break;
  71.     case SD_CARD_TYPE_SD2:
  72.       Serial.println("SD2");
  73.       break;
  74.     case SD_CARD_TYPE_SDHC:
  75.       Serial.println("SDHC");
  76.       break;
  77.     default:
  78.       Serial.println("Unknown");
  79.   }
  80.  
  81.   // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  82.   if (!volume.init(card)) {
  83.     Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
  84.     return;
  85.   }
  86.  
  87.  
  88.   // print the type and size of the first FAT-type volume
  89.   uint32_t volumesize;
  90.   Serial.print("\nVolume type is FAT");
  91.   Serial.println(volume.fatType(), DEC);
  92.   Serial.println();
  93.  
  94.   volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  95.   volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  96.   volumesize *= 512;                            // SD card blocks are always 512 bytes
  97.   Serial.print("Volume size (bytes): ");
  98.   Serial.println(volumesize);
  99.   Serial.print("Volume size (Kbytes): ");
  100.   volumesize /= 1024;
  101.   Serial.println(volumesize);
  102.   Serial.print("Volume size (Mbytes): ");
  103.   volumesize /= 1024;
  104.   Serial.println(volumesize);
  105.  
  106.  
  107.   Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  108.   root.openRoot(volume);
  109.  
  110.   // list all files in the card with date and size
  111.   root.ls(LS_R | LS_DATE | LS_SIZE);
  112. }
  113.  
  114.  
  115. void loop(void) {
  116.  
  117. }



Se non funziona hai probabilmente dimenticato di fare qualcosa sull'hardware.


Il mio blog: https://piero.dev
PM Quote
Avatar
alex1995 (Normal User)
Expert


Messaggi: 294
Iscritto: 27/01/2011

Segnala al moderatore
Postato alle 13:52
Martedì, 06/01/2015
mi esce quest' errore:

Codice sorgente - presumibilmente Delphi

  1. initialization failed. Things to check:
  2. * is a card is inserted?
  3. * Is your wiring correct?
  4. * did you change the chipSelect pin to match your shield or module?



io ho solo collegato l' ethernet shield che funziona, si deve fare altro?
e per la scheda sd è giusto dare il pin 53 a SD.begin sull arduino mega 2560?

PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 17:14
Martedì, 06/01/2015
Testo quotato


On the Mega, the hardware SS pin, 53, is not used to select either the W5100 or the SD card, but it must be kept as an output or the SPI interface won't work.



Hai cambiato questa linea?

Codice sorgente - presumibilmente Sistemi integrati

  1. pinMode(10, OUTPUT);     // change this to 53 on a mega


Ultima modifica effettuata da pierotofy il 06/01/2015 alle 17:14


Il mio blog: https://piero.dev
PM Quote
Avatar
alex1995 (Normal User)
Expert


Messaggi: 294
Iscritto: 27/01/2011

Segnala al moderatore
Postato alle 12:56
Mercoledì, 07/01/2015
si l' ho provata col 10 e col 53 siccome c' è scritto che sul mega è 53

PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 16:43
Mercoledì, 07/01/2015
Mm, se la scheda e' inserita correttamente e il chipSelect è giusto, l'unico altro problema è il wiring (ma essendo uno shield quello dovrebbe essere già a posto).

Sarebbe interessante provare a collegare lo shield su un'altra board per vedere se il problema è lì.


Il mio blog: https://piero.dev
PM Quote
Avatar
alex1995 (Normal User)
Expert


Messaggi: 294
Iscritto: 27/01/2011

Segnala al moderatore
Postato alle 19:56
Mercoledì, 07/01/2015
tutto risolto era la microsd

PM Quote
Avatar
pierotofy (Admin)
Guru^2


Messaggi: 6230
Iscritto: 04/12/2003

Segnala al moderatore
Postato alle 20:22
Mercoledì, 07/01/2015
:k:


Il mio blog: https://piero.dev
PM Quote
Avatar
alex1995 (Normal User)
Expert


Messaggi: 294
Iscritto: 27/01/2011

Segnala al moderatore
Postato alle 21:13
Mercoledì, 07/01/2015
grazie :), ho un altro problema con questo codice che quando lo uso mi da errore. ma non quando lo compilo

Codice sorgente - presumibilmente C#

  1. void setup()
  2. {
  3. pinMode(53, OUTPUT);
  4. SD.begin(53);
  5. Serial.begin(9600):
  6. }
  7. void scriviFile(char *nomeFile, String datiFile)
  8. {
  9.   File scriviFile  = SD.open(nomeFile, FILE_WRITE);
  10.   if(scriviFile)
  11.   {
  12.     scriviFile.println(datiFile);
  13.     scriviFile.close();
  14.     Serial.write("ok");
  15.   }
  16.   else
  17.   {
  18.     Serial.write("errore");
  19.   }
  20. }


PM Quote
Pagine: [ 1 2 ] Precedente | Prossimo