How to write RAW data to specific address of memory card and read from it

hello everyone,

I want to write my 512 byte array into known address of memory card using SPI bus
I think I can't do it using SD.h library,

How can I do it?
Can I do it by modifying SPI library only?
or any simple fast library that do not use FAT file system?

thanks

It would be helpful to know what problem you are trying to solve.

This seems like the sort of application where an EEPROM might be more appropriate... (eg, AT24-series, if not the onboard eeprom)....

In any event, it is possible - albeit not with the normal library. Google around - someone's probably done it on arduino (a very quick search revealed people talking about doing it with PIC)

You could write to known offsets inside a file, which should be supported by the library.

I have issue with reliability of FAT system.
because if data was corrupted we dont know where it is.
so i am going to write data by addressing the location. so I know the exact place.

I couldn't find library by googling.

I doubt that the FAT system is unreliable.

It is not immune to card removal, resets and crashes before cache write-back.

PS. I have some issues with error descriptions of the type 'I have some issues'.

As far as I know there is nothing to prevent you writing to an SD Card without using the FAT system. Of course the data will not be readable on another device - which may be a problem or an advantage.

...R

frechi91:
How can I do it?
Can I do it by modifying SPI library only?
or any simple fast library that do not use FAT file system?

If access time and writing time is not an issue, the simplest solution would be:

  • format an SD card
  • as the first file operation, create one maximum size file, that should be 2 GB size
  • if you never change the file size afterwards, no write operations in the FAT will occur after that
    All FAT sectors of that file should then be consecutive sectors on SD card, and it should be impossible that any FAT system will get out of sync with a file of consecutive sector numbers.

You then can write at any offset into the file where you like.

When using a FAT tool to find out which is the first sector of that file, all other sectors belonging to the file should be consecutive sector numbers.

Actually speed is necessary. I achieved 2KHZ speed with arduino due. where I used sdfat libary.
Now I got a code to write directly to SD.
but it is very slow.

now I can't even write 1khz speed. is FAT system is speeder than direct accessing?

Can I speed up SPI by editing SPI settings? (ex: clock divider?)

Now I got a code to write directly to SD.

Can you please share it with us.

frechi91:
Actually speed is necessary. I achieved 2KHZ speed with arduino due. where I used sdfat libary.
Now I got a code to write directly to SD.
but it is very slow.

now I can't even write 1khz speed. is FAT system is speeder than direct accessing?

Can I speed up SPI by editing SPI settings? (ex: clock divider?)

You can write "big blocks" to SD card at about 100 KByte/s average write rate with 8-bit controllers like Atmega328.

High write rates require, that you avoid "single byte writes".
High write rates require "block write" of data blocks, perhaps 64 bytes size minimum at once. Or in case you have the data in a 512-byte array, write that in a single write call, 512 bytes is one sector on SD card.

High write rates also require to keep the file opened between writes. So don't close/open a file too often.

A quick look at the storage section of the playground will tell you all you need to know

Mark