Comments (6)
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.
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.
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.
thanks!,
- the SD_POW pin is connected to ~SHDN of the LT1962-3.3
- with
while (sd.card()->isBusy());
instead ofdelay(100);
it work!
from sdfat.
the sandisk extreme pro:
https://www.sandisk.com/home/memory-cards/microsd-cards/extremepro-microsd
draws about 300µA in sleep mode
from sdfat.
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)
- Did not work at ESP32-CAM HOT 6
- MMC_ERASE HOT 2
- Wrapper to fs::FS to use SDfat in ESPAsyncWebserver HOT 6
- pico-sdk only rp2040 implementation HOT 7
- ESP32 S3 always fails to mount card HOT 10
- Unable to format flat Spiflash module with ESP8266 HOT 4
- Mount issues for a Windows-formatted card HOT 35
- SD NAND XTSD01G (surface mounted chip) not formating HOT 1
- Unable to share the same SPI bus with TFT_eSPI on ESP32 HOT 1
- Problems with multiple SD card HOT 3
- Long timeout calling begin() on Teensy 4.1 when no card present HOT 5
- SdFat 2.22 with USER_SPI1 pin + another USER_SPI2 in SPI_Mode3 HOT 2
- Arduino-Pico: huge slowdown with v2.2.2 (vs.2.1.1) HOT 5
- Problem with SdFat and TwoWire instance. HOT 3
- sd.begin(SPI_CONFIG) breaks my DMA ADC datalogger on the SAMD51 HOT 5
- Issue after latest update. HOT 17
- exFat sd cards not working with Sdinfo.ino example, only FAT32 card HOT 7
- Allocating bin file with 0s HOT 2
- CS_Pin has to be driven high on ESP32 (to be low at the SDCARD) because of some logic inbetween HOT 3
- Initialization fails with ESP32 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdfat.