Exemplo n.º 1
0
int initialSDCard()
{
  //SPI speed: 0 - F_CPU/2, 1 - F_CPU/4
  if (!card.init(0,SD_CS_PIN))
  {
    error("card.init failed");
    return 0;
  }
  // initialize a FAT16 volume
  if (!Fat16::init(&card))
  {
    error("Fat16::init");
    return 0;
  }
  return 1;
}
Exemplo n.º 2
0
unsigned char newSD::init()
{
  //SPI speed: 0 - F_CPU/2, 1 - F_CPU/4
  if (!card.init(1,SD_CS_PIN))
  {
    error("card.init failed");
    return 0;
  }
  // initialize a FAT16 volume
  if (!Fat16::init(&card))
  {
    error("Fat16::init");
    return 0;
  }
  return 1;
}
Exemplo n.º 3
0
void logInit() {
    // initialize the SD card
    if (!card.init()) { 
        Serial.print("Error initializing card - ");
        Serial.println(card.errorCode, HEX);
        return;
    }
    
    // initialize a FAT16 volume
    if (!Fat16::init(&card)) {
        Serial.println("Can't initialize volume.");
        return;
    }
    
    // create a new file
    char name[] = "LOGGER00.TXT";
    for (uint8_t i = 0; i < 100; i++) {
        name[6] = i/10 + '0';
        name[7] = i%10 + '0';
        // O_CREAT - create the file if it does not exist
        // O_EXCL - fail if the file exists
        // O_WRITE - open for write only
        if (file.open(name, O_CREAT | O_EXCL | O_WRITE)) break;
    }

    if (!file.isOpen()) {
        Serial.println("Error creating log file.");
        return;
    }
    
    Serial.print("Logging to: ");
    Serial.println(name);

    // write data header
    
    // clear write error
    file.writeError = false;
    file.println("Started log.");
    file.sync();
    
    fileReady = 1;
}