Is it possible to use an SD card as plain memory?

Hi all,

I know that there are “SD” libraries for Arduino that can use an SD card as a disk drive. But what I would like to know is, can an SD card be simply used as EXTERNAL RANDOM ACCESS FLASH MEMORY?

That is, can I just send it an “Address” SPI command, then a “Read” or “Write” command in SPI and read/write the SD card (in a similar manner to how an external SPI flash chip is accessed)?

Even if I need to read or write in specific sized blocks, that’s OK as well.

What I want to do it this: I already have an 8 bit D to A converter made from an R-2R ladder. I can do this successfully:

    DDRK = 0xFF; // set port as output
    for (addr = start; addr < end; addr++) {
        PORTK = pgm_read_byte_far (addr); // send audio byte to DAC
        _delay_us (1e6 / 11025); // proper delay between samples
    }

But of course I’m limited to 256K of flash minus the bootloader minus the sketch = barely enough room for 30 seconds of 8000 samples per second 8 bit mono sound.

I want to instead put my audio data on an SD card and then read the data, sending it directly to the port as I do now. The point, obviously, is that I can store a LOT more sound samples on an SD card.

I don’t want to access the SD card as a disk using the SD library because every time I read another block of data into a buffer to play more, the sound will stop momentarily. I could probably “ping-pong” between two buffers, filling one while reading the other using an ISR, but it would be a lot simpler if I could just read directly from the SD card as flash memory.

Any ideas will be appreciated!

Thanks!

Check out what fat16lib got working with me here two summers ago: http://forum.arduino.cc/index.php?topic=180769.0

CrossRoads:
Check out what fat16lib got working with me here two summers ago:
http://forum.arduino.cc/index.php?topic=180769.0

OK, I downloaded your sketch and glanced through it. It seems as though you are recording and playing back audio via SPI SRAM as well as “planning to use the SD card someday”… :slight_smile:

What I want to do is use an SD card as flash memory, not as a disk drive. For example, I might take some digitized audio data and using the “dd” command in Linux, write the audio file to the SD card starting at byte zero.

Then putting the SD card back into the Arduino, I would do something like this (pseudo-code):

for (x = 0; x < filesize; x++) {
    set_sd_card_address (x);
    data = get_sd_card_data ();
    PORTK = data; // this is where my DAC is connected
    _delay_us (TBD); // for proper playback rate
}

See what I’m getting at? I want to access the SD card directly, raw… not as a disk drive using SD or SDFAT or whatever.

That’s what I’m looking for information on. I could probably figure it out myself, but why re-invent the wheel if someone else has already done it?

I doubt it. The interface is designed to emulate a disk drive.

Also keep in mind that flash has a limited number of write cycles, so not to write to the same spot many many times.

Once you have the card initialized, reading takes this form:

  1. send a read block command with the 32-bit block address
  2. wait for response from SD card
  3. read in the data packet with the block (512 bytes or larger)

That’s what SD does.