# How fast is a SD page read from a file?

For a project I would like to do, I asked a question about whether to use SD or EEPROM (see Question

I checked how much memory I would need without any restrictions which is like 2 MB (or more) so a SD card seems the best solution.

However, I'm a bit worried about the speed. In one of the answer comments is mentioned that 20 ms is an eternity for a microcontroller. However, I might need to do the following within 20 ms:

1. Parse a MIDI event (CPU power only, does not take long)
2. Read one or two SD pages (1/2 times block of 512 bytes)
3. Change/add/remove the MIDI event (CPU power only, negligible)
4. Send out MIDI data (barely no time, mostly hardware)

In worst case I can get like 10-20 MIDI events I need to handle within 20 ms. Especially for step 2 I don't know how much time it will. My plan is to create a big file with a PC program to be stored on the SD card. Than I can let the Arduino read pages of 512 bytes from predefined places (with seek in a file).

I'm intending to keep the file open at all times and use seeks to go to the right place and read 512 bytes every time (assuming it doesn't matter to read 1 or 512 bytes since the page size is 512 bytes anyway).

So my question: is 20 ms enough to read like 50 pages of 512 bytes from an SD card which are located on different (but known) file offsets within a 2+ MB file?

(btw, I want to try first on an Uno, but probably I will later go to a Mega (or add more SRAM to store temporary data).

So my question: is 20 ms enough to read like 50 pages of 512 bytes from an SD card which are located on different (but known) file offsets within a 2+ MB file?

Let us do the numbers: 50 * 512 = 25 Kbyte in 20 ms is 1.25 Mbyte/s. As the max speed for SPI is 1 Mbyte/s (on Arduino AVR, 16 MHz) we do not have to go any further. The answer is: No.

Cheers!

• Thanks for this answer, although the answer is no, still 40 pages per second is feasible which still is ok (but not optimal). Just hope it doesn't matter to read non-contiguous blocks for the max spee of 1 MB/s and the seeks don't take too much time. Mar 10, 2017 at 10:43
• No, there is much more going on when accessing an SD. You should count on 200-300 Kbyte/s max substained. The SD SPI protocol requires both synchronization and addressing so the effective bandwidth is lower. High speed SD uses multiple data pins (and additional hardware support). Mar 10, 2017 at 10:48
• that would mean a page read of 512 bytes would take 2.5 ms? And 512 bytes is the minimum amount to read I read somewhere. Mar 10, 2017 at 11:11
• @MikaelPatel: would it be possible to use 2 sdcards and 2 SPI buses to (almost) double the throughput? Mar 11, 2017 at 14:05

Just for reference for others:

I received my micro card reader (from Catalex, v1.0, 11/01/2013) today and used a 1GB micrSD card.

The times measured ar at 4 addresses (2000, 120000, 40000 and 12000) again and are a seek to the address, and the reading of the bytes mentioned before the colon and the time after the colon in micros.

Result: Seek is 25..2500 micros depending on the file position, reading below 256 bytes is approx. 2-3 ms, reading 256 bytes 4-6 and 512 bytes 7-8 ms.

``````Initializing SD card...card initialized.
---------
seek    : 24
-----------
seek    : 2536
---------
seek    : 2468