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

sdCard.h

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 that 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!
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. Unsurprisingly:- if you try doing it then the computer may report all sorts of errors.
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.
Whichever mode you use then you will need to call 'sdCardInit' to initialise the card.
For 'stand alone' format then you are limited to the sdCardRead and sdCardWrite functions described below.
If you would prefer to use 'Computer format' then refer to FileSystem/FAT.h

 

Function

 


SD_CARD MAKE_SD_CARD(const IOPin* select)

Create an SD memory card device.
The parameter is the IO pin used to select the device (ie connected to the CS pin of the card).

boolean sdCardInit(SD_CARD* card)

Initialise the SD card.

boolean sdCardRead(SD_CARD* card,uint32_t absSector,void* dta,uint8_t numSectors)

Read a 512 byte sector from the card.

boolean sdCardWrite(SD_CARD* card, uint32_t absSector,const void* dta,uint8_t numSectors)

Write a 512 byte sector of data to the card.

STORAGE_CLASS* sdCardGetStorageClass(void)

Returns the STORAGE_CLASS for SD cards.
This is used by diskInit(DISK *disk, uint8_t numBuffers, const STORAGE_CLASS* class, void* device) if you want to use the card as a disk drive.

Valid XHTML 1.0 Transitional