WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

SD Card

Provides storage on an SD card or the phased out MMC card.
An SD card is like a miniature EEPROM accessed via the SPI interface. They are also available as micro SD cards which, physically, are much smaller. You may be familiar with them as they provide the 'memory' for your digital camera or your hand held phone.
Here is a typical pin out of the bare card:-
 /  1 2 3 4 5 6 78 | <- view of SD card looking at contacts
/ 9                | Pins 8 and 9 are present only on SD cards and not MMC cards
|        SD Card   |
|                  |
1 - CS   (chip select)          - wire to any available I/O pin
2 - DIN  (data in, card<-host)  - wire to SPI MOSI pin
3 - VSS  (ground)               - wire to ground
4 - VDD  (power)                - wire to 3.3V power
5 - SCLK (data clock)           - wire to SPI SCK pin
6 - VSS  (ground)               - wire to ground
7 - DOUT (data out, card->host) - wire to SPI MISO pin
The cards are available in various capacities from a few Mb to umpteen Gb - so can certainly hold more data than your processor can hold in memory.
Why would I need one? These guys can store a lot of info - and like an EEPROM their data is 'saved' even when the power is off. So they are great for storing any kind of logging or data acquisition. But, unlike an EEPROM, they are removable and can be physically removed and plugged into other things - including your computer!
If we were to make the analogy that these devices are like mini bank cards then we also need a mini ATM to plug them into so that they can be read. (No worries - they don't know your banking info!)
The ATM will not only provide power (normally 3v3) but may also provide a digital IO output pin to indicate if a card has been inserted (called 'card detect').
Here is an example from SparkFun http://www.sparkfun.com/commerce/product_info.php?products_id=204
Lots of other boards are available and some can even generate the 3v3 supply via a regulator and may be powered from, say, +5v.
But the beauty of these devices is that you can also plug them into a USB carrier and plug that into your computer and use it like a memory stick. For example: http://www.sparkfun.com/commerce/product_info.php?products_id=8698
Ok - enough advertising!
In Project Designer you must must add the SD Card to an existing SPI Bus.
WebbotLib allows you to access these cards in one of two modes:
1. Stand alone
2. Computer format
In 'stand alone' format your code will be smaller but all you can do is read/write from/to a given 512 byte sector block number on the card. This 'custom' format means that the card will NOT be recognised if it is plugged into a computer (unless it is re-formated). Unsurprisingly:- if you try doing it then the computer may report all sorts of errors. However: you could write a small program on your micro-controller to dump the card content over a UART to your PC.
In 'computer format' the generated code will be bigger but will mean that you can transfer the card to your computer and it will be able to read it and vice versa. ie it becomes a removable hard disk drive. However: before it can be used then you must format it from your computer. I suggest using a program such as: http://www.sdcard.org/consumers/formatter/ to do that.
The mode can be set in Project Designer via the 'Formatted for PC use?' checkbox. If ticked then it will use 'computer format' otherwise it will use 'stand alone' format.
For 'stand alone' format then you are limited to the read and write functions.
For 'computer format' Project Designer will create a variable called 'disk_xxxx' where 'xxxx' is the name you have given the card in Project Designer. This allows you to manipulate files on the disk using the functions in Disk.
Function Summary

Valid XHTML 1.0 Transitional