Joined: 25 Jul 2007 Posts: 284 Location: PA near Philly
Posted: Tue Aug 18, 2009 2:19 am Post subject: Reading/writing a 512 byte blocks with a MMC/SD card
Josef,
Is it possible to use just the lower level MMC/SD read & write routines without the full FAT routines? I would like to be able to read/write the 512 byte blocks and save all the program space that the fat routines use up.
You can use Drivereadsector and Drivewritesector to read and write arbirtary sectors into/from a 512 byte array. This is handy if you just want to write a single massive stream of data (eg data logger).
You will destroy any FAT/FAT32 formatting on the card if you simply write sectors starting from 0, but it's a very easy way to get massive storage space. You can perhaps use EEPROM or the first sector on the card to store a simple table of how many sectors you've written to.
You can read this data into a PC if you use a low-level disk reader/editor (hex editor) such as the free DiskImage.
Code:
Dim Berror AsByte Dim Abuffer(512)asByte' Hold Sector to and from SD Card Dim Wsrampointer AsWord' Address-Pointer for read/write Dim Lsectornumber AsLong' Sector Number
' give Address of first Byte of the 512 Byte Buffer to Word-Variable
Wsrampointer =Varptr(abuffer(1))
' Set Sectornumber
Lsectornumber =0
' Read in sector from card
Berror =Drivereadsector(wsrampointer , Lsectornumber)
'Hex dump of sector For I =1To512 PrintHex(abuffer(i)); Next I
' Now write buffer to another sector on card
Lsectornumber =1
Berror =Drivewritesector(wsrampointer , Lsectornumber)
_________________ If all else fails, read the manual. Even better: read the manual before something fails. If you can't find it in the manual, search the forum.
BascomAVR 2.0.8.5
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum