Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Reading/writing a 512 byte blocks with a MMC/SD card

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS
View previous topic :: View next topic  
Author Message
glena

Bascom Member



Joined: 25 Jul 2007
Posts: 284
Location: PA near Philly

usa.gif
PostPosted: Tue Aug 18, 2009 2:19 am    Post subject: Reading/writing a 512 byte blocks with a MMC/SD card Reply with quote

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.

Thanks,

-Glen

_________________
http://bahbots.com
Back to top
View user's profile AIM Address
mattcro

Bascom Member



Joined: 03 Oct 2007
Posts: 327
Location: Scotland

uk.gif
PostPosted: Tue Aug 18, 2009 10:40 am    Post subject: Reply with quote

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 As Byte
Dim Abuffer(512)as Byte                                     ' Hold Sector to and from SD Card
Dim Wsrampointer As Word                                    ' Address-Pointer for read/write
Dim Lsectornumber As Long                                   ' 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 = 1 To 512
   Print Hex(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
Back to top
View user's profile
glena

Bascom Member



Joined: 25 Jul 2007
Posts: 284
Location: PA near Philly

usa.gif
PostPosted: Tue Aug 18, 2009 2:21 pm    Post subject: Reply with quote

Thanks mattcro!

This is exactly what I was looking for!

-Glen

_________________
http://bahbots.com
Back to top
View user's profile AIM Address
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> AVR-DOS All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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