It takes about 2msec to read the first byte from a MicroSD card file using the Arduino Uno all subsequent bytes take microseconds. Why is that? Is there a way to avoid it since my project can't afford a 2msec delay? I read online that the first read sets up the timing, if true is there a way to re-read the first byte? I need to read the first byte and all other bytes in microseconds once a timing signal is received.
Is it reading the first byte that takes time or is it opening the file and reading the first byte?
It is reading of the first byte that takes the time. I put a 1000msec delay between SD.open and the first read() and it had no effect.
SONG = SD.open("SONG.txt", FILE_READ); // open file for reading:
delay(1000);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
digitalWrite(latchPin, HIGH);
Always use code tags when posting code.
Try this:
SONG = SD.open("SONG.txt", FILE_READ); // open file for reading:
byte first = SONG.read();
delay(1000);
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, first);
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
shiftOut(dataPin, clockPin, MSBFIRST, SONG.read());
digitalWrite(latchPin, HIGH);
It will also take more time when the next byte must be read from the next 512 byte block of data from the SD card.
That is JUST THE WAY IT WORKS!
Ok, what about using NOR flash? It doesn't uses pages/blocks and you can read it faster than NAND flash.
https://www.amazon.com/W25QXX-DataFlash-W25Q128JV-Onboard-Interface/dp/B01C84AJKQ
My file sizes are under 2MB
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
