La biblioteca SD de Arduino no funciona con Proteus: la tarjeta SD no se inicializa.

TheSiffer910 Mensajes publicados 124 Estado Miembro -  
 Darkairy -
Hola,

Quiero simular un lector de tarjetas SD en Proteus. Ya hice el programa pero cuando inicio la simulación, el Virtual Terminal (Puerto Serie) me devuelve un mensaje de error codificado para saber si la tarjeta SD está accesible.
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
}

Lo escribí en el void setup, ya declaré chipSelect como OUTPUT y he incluido la librería SD de Arduino (ver el código completo más adelante). Sin embargo, el Virtual Terminal imprime "Card failed, or not present", aunque la tarjeta está presente.
Adjunté algunas capturas de Proteus.
Además, cuando codifico esto:
Sd2Card card;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only

pinMode(chipSelect, OUTPUT);
}
Serial.print("Initializing SD card...");

// see if the card is present and can be initialized:
if (!card.init()) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
}

esta fase se ejecuta bien y sí muestra "card initialised" pero más tarde aparece "error opening datalog.txt" (ver más abajo en el código completo).
Concluí que Proteus no entiende la librería SD de Arduino y por lo tanto no entiende "SD.begin()" y SD.open().
Si alguien pudiera ayudar sería bienvenido porque estoy atascado.

Aquí está el código completo (no final, pero todo está ahí para la tarjeta SD):
int VSIG_num = A0; /* The numerical converted value of the received voltage is an integer
and will be read on the analogical pin 0 (later defined as an analogical input) */
int VSIG_read = 0; // VSIG_read is the numerical value Arduino gives to VSIG, between 0 and 1023
int VSIG = 0; // The actual value of the output voltage of the sensor, later calculated
int intensity = 0; // The value we seek to find, luminous intensity

#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only

pinMode(chipSelect, OUTPUT);
}

Serial.print("Initializing SD card...");

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
}

void loop() {

long sum = 0;
for(int i=0;i<1024;i++) // Used here to make an average of the value
{
VSIG_read = analogRead(VSIG_num); // Obtains the numerical value of VSIG given by Arduino
sum = VSIG_read+sum;
delay(2);
}
sum = sum >> 10; // Divides the total by 1024 to make the average (10 bits shift = /1024)
VSIG = sum*5/1024; // Calculates the actual value of the output voltage of the sensor
intensity = 307*VSIG; // Calculates the luminous intensity according to the given calculation

String dataString = "";
dataString += String(intensity);
dataString += ",";

File dataFile = SD.open("datalog.txt", FILE_WRITE);

if (dataFile) {
dataFile.println(dataString);
dataFile.close();
Serial.println(dataString);
}
else {
Serial.println("error opening datalog.txt");
}
}


Merci d’avoir pris le temps de lire cela. Je tiens aussi à ajouter que j’ai la dernière version de la bibliothèque SD. Les captures sont en commentaire, je les avais oubliées.

2 respuestas

  1. TheSiffer910 Mensajes publicados 124 Estado Miembro 8
     
    Las capturas de Proteus
    0
  2. Darkairy
     
    ¡Oye! ¿Ya encontraste la solución? Tengo exactamente el mismo problema x)
    0