Coder Social home page Coder Social logo

Comments (6)

greiman avatar greiman commented on July 22, 2024

I have no idea why your program does not work.

I create the empty file Q0000000.QLS on a Windows 10 computer using an SD formatted with the SD association's SD formatter.

I run this program using the latest SdFat beta.

#include "SPI.h"
#include "SdFat.h"

void setup() {
  Serial.begin(9600);
  Serial.println("Type any character to remove file");
  while(!Serial.available());
  SdFat sd = SdFat();
  if (!sd.begin(10)) {
    Serial.println("begin Failed");
    return;
  }
  if (!sd.exists("Q0000000.QLS")) {
    Serial.println("file not found");
    return;
  }
  if (!sd.remove("Q0000000.QLS")) {
    Serial.println("Remove failed");
  } else {
    Serial.println("File Removed");
  }
}
void loop() {
}

The program prints

Type any character to remove file
File Removed

The file is not on the SD.

Note: I don't use Linux for formating SD cards or creating tests for SdFat since there are bugs in the FAT implementation.

I do use Mint Linux but don't want to pursue this issue unless you can give me an example that fails.

from sdfat.

lsaavedr avatar lsaavedr commented on July 22, 2024

I now understand the problem, but I don' know if you can reproduce this, the code is this:

#define SD_POW 14

#define SD_CS 10
#define SD_SCK 13
#define SD_MOSI 11
void setup() {
  // SD power off:
  pinMode(SD_CS, OUTPUT); digitalWrite(SD_CS, LOW);
  pinMode(SD_SCK, OUTPUT); digitalWrite(SD_SCK, LOW);
  pinMode(SD_MOSI, OUTPUT); digitalWrite(SD_MOSI, LOW);
  pinMode(SD_POW, OUTPUT); digitalWrite(SD_POW, LOW);

  while(!Serial.available());
  while(Serial.available()) Serial.read();

  digitalWrite(SD_POW, HIGH); // SD power on
  delay(200); // In SD-standard is 200ms, right? (this work fine)

  SdFat sd = SdFat();
  sd.begin(SD_CS, SPI_FULL_SPEED); // in this SD_CS, SD_SCK and SD_MOSI are reconfigured

  if (sd.remove("Q0000000.QLS")) {
    Serial.println("remove ok"); // is always true!!!
  } else {
    Serial.println("remove fail");
  }

  // SD power off:
  // delay(100); // What does the SD standard say about this? (with 100ms it work fine)
  pinMode(SD_CS, OUTPUT); digitalWrite(SD_CS, LOW);
  pinMode(SD_SCK, OUTPUT); digitalWrite(SD_SCK, LOW);
  pinMode(SD_MOSI, OUTPUT); digitalWrite(SD_MOSI, LOW);
  pinMode(SD_POW, OUTPUT); digitalWrite(SD_POW, LOW);
}
void loop() {}

the problem is caused by de-energizing the SD prematurely due to power control, with a delay(100) it work fine, but what does the SD-standard say about this?

from sdfat.

greiman avatar greiman commented on July 22, 2024

The standard says reliably removing power is not supported in SPI mode. It does suggest that you can remove power one second after the card goes not busy but does not guarantee this will work.

You can check for busy like this. This is used in several SdFat examples like the LowLatencyLogger at about line 441.

if (sd.card()->isBusy()) {
}

Also you should not power the card with a gpio pin. Write can occasionally require more current than a pin can supply. You may see data errors.

SdFat leaves cards in the mode where they can go into low current sleep mode. For most cards sleep mode draws about 100 µA.

Users have powered a low power logger for up to a year with three AA batteries.

https://edwardmallon.wordpress.com/2014/07/01/a-10-diy-data-logger-is-born/

from sdfat.

lsaavedr avatar lsaavedr commented on July 22, 2024

thanks!,

  1. the SD_POW pin is connected to ~SHDN of the LT1962-3.3
  2. with while (sd.card()->isBusy()); instead of delay(100); it work!

from sdfat.

lsaavedr avatar lsaavedr commented on July 22, 2024

the sandisk extreme pro:

https://www.sandisk.com/home/memory-cards/microsd-cards/extremepro-microsd

draws about 300µA in sleep mode

from sdfat.

greiman avatar greiman commented on July 22, 2024

You can't depend on isBusy() to power down a card. It only means the card can accept a command. It may still be programming flash or moving data for wear-leveling. You really need the one second delay after not busy.

The sandisk extreme pro may not be a good choice for SPI mode. Often lower cost cards perform better in SPI mode. SPI mode is an after thought for high end cards, required by the SD spec. Cards with good SPI performance often sleep at lower current.

Also, the trade-off between powering down a card and sleep is not simple. Cards draw lots of current during initialization, often 100 times the sleep current. Depends on the access pattern to the card and the time to initialize your card.

Also SdFat performs better over the long term if you do not init the SD card often. It remember things like where it should search for the next free cluster. It is better not to open large files and seek to the end. sync() is equivalent to close()/open() but no directory search is required.

from sdfat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.