AtomSoft
Well-Known Member
Ok i have a bunch of PIC micros and most with small amounts of memory and the large PICs are overkill so i was thinking of a way to use a SD Card without needing alot of memory.
This will work well for reading ONLY! no write feature unless you are writing RAW data. But no FILE access tho since it requires to write 512 bytes. I got a theory on this too tho.
Ok to READ with small amount of memory... well a custom amount even 1 byte!
EDIT:
To write we would need 1 512 buffer since we can only write 512 block and the SD handles that so we can just ask it to skip... (not tha ti know of lol)
This will work well for reading ONLY! no write feature unless you are writing RAW data. But no FILE access tho since it requires to write 512 bytes. I got a theory on this too tho.
Ok to READ with small amount of memory... well a custom amount even 1 byte!
Code:
int readCustom( LBA a, unsigned int start,unsigned int length, char *p)
// a LBA of sector requested
// p pointer to sector buffer
// start Start Byte
// length Length of bytes
// returns TRUE if successful
{
int r, i;
int x;
x = (512 - length) - start;
READ_LED = 0;
// 1. send READ command
r = sendSDCmd( READ_SINGLE, ( a << 9));
if ( r == 0) // check if command was accepted
{
// 2. wait for a response
for( i=0; i<R_TIMEOUT; i++)
{
r = readSPI();
if ( r == DATA_START)
break;
}
// 3. if it did not timeout, read 512 byte of data
if ( i != R_TIMEOUT)
{
for(i=0;i<start;i++) //Skip the bytes until we hit our start byte
readSPI();
i = length; //get our bytes using the length as a count
do{
*p++ = readSPI();
} while (--i>0);
// 4. ignore CRC
readSPI();
readSPI();
for(i=0;i<x;i++) //skip the rest if any
readSPI();
} // data arrived
} // command accepted
// 5. remember to disable the card
disableSD();
READ_LED = 1;
return ( r == DATA_START); // return TRUE if successful
} // readSECTOR
EDIT:
To write we would need 1 512 buffer since we can only write 512 block and the SD handles that so we can just ask it to skip... (not tha ti know of lol)
Last edited: