Writing to SDCard using SPI

General discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
DavidFrans
Posts: 9
Joined: 08 Oct 2009 14:14
Location: Belgium

Writing to SDCard using SPI

#1 Post by DavidFrans » 03 Mar 2013 21:39

Hello all,

I hope I'm posing in the right section here. I would like to log data from a sensor to an SDCard. I read an interesting idea on AVRFreaks in order to keep the microcontroller requirements and code complexity low. There was a suggestion to format an SDCard, create a single, very large file on it, and then use this card to log the data, only having to worry about writing to the correct address, not about the FAT complexity. This would work perfectly for me, even having to read out the data using a hex editor would be sufficient. It also prevents me from using the MMC libraries requiring a much larger microcontroller.

I've never used the SPI library before, nor am I familiar with SDCard communication. For the latter I found an interesting manual here: http://elm-chan.org/docs/mmc/mmc_e.html

In the MikroBasic documentation of the SPI library there is an example about writing only, it would be interesting to see an example about reading. I suppose this needs to work with some kind of interrupt right? Has anyone an example that they want to share?

In case anyone has experience with MMC and SDCards: The manual that I found talks about a data block that is transferred as a data packet consisting of a Token, Data Block and CRC. Is this all implemented in SPI, or do I have to send several SPI packages? Also they mention about commands, e.g. CMD24. Does that mean I have to send the decimal value of 24 as data?

Thank you for getting me started,

David

Post Reply

Return to “mikroBasic PRO for AVR General”