Public Member Functions
Sd2Card Class Reference

Raw access to SD and SDHC flash memory cards. More...

#include <Sd2Card.h>

List of all members.

Public Member Functions

 Sd2Card (void)
 Construct an instance of Sd2Card.
uint32_t cardSize (void)
 Determine the size of an SD flash memory card.
uint8_t erase (uint32_t firstBlock, uint32_t lastBlock)
 Erase a range of blocks.
uint8_t eraseSingleBlockEnable (void)
 Determine if card supports single block erase.
uint8_t errorCode (void) const
uint8_t errorData (void) const
uint8_t init (void)
 Initialize an SD flash memory card with default clock rate and chip select pin.
uint8_t init (uint8_t sckRateID)
 Initialize an SD flash memory card with the selected SPI clock rate and the default SD chip select pin.
uint8_t init (uint8_t sckRateID, uint8_t chipSelectPin)
 Initialize an SD flash memory card.
void partialBlockRead (uint8_t value)
 Enable or disable partial block reads.
uint8_t partialBlockRead (void) const
 Returns the current value, true or false, for partial block read.
uint8_t readBlock (uint32_t block, uint8_t *dst)
 Read a 512 byte block from an SD card device.
uint8_t readData (uint32_t block, uint16_t offset, uint16_t count, uint8_t *dst)
 Read part of a 512 byte block from an SD card.
uint8_t readCID (cid_t *cid)
 Read a cards CID register.
uint8_t readCSD (csd_t *csd)
 Read a cards CSD register.
void readEnd (void)
 Skip remaining data in a block when in partial block read mode.
uint8_t setSckRate (uint8_t sckRateID)
 Set the SPI clock rate.
uint8_t type (void) const
 Return the card type: SD V1, SD V2 or SDHC.
uint8_t writeBlock (uint32_t blockNumber, const uint8_t *src)
 Writes a 512 byte block to an SD card.
uint8_t writeData (const uint8_t *src)
 Write one data block in a multiple block write sequence.
uint8_t writeStart (uint32_t blockNumber, uint32_t eraseCount)
 Start a write multiple blocks sequence.
uint8_t writeStop (void)
 End a write multiple blocks sequence.

Detailed Description

Raw access to SD and SDHC flash memory cards.

Definition at line 152 of file Sd2Card.h.


Constructor & Destructor Documentation

Sd2Card::Sd2Card ( void  ) [inline]

Construct an instance of Sd2Card.

Definition at line 155 of file Sd2Card.h.


Member Function Documentation

uint32_t Sd2Card::cardSize ( void  )

Determine the size of an SD flash memory card.

Returns:
The number of 512 byte data blocks in the card or zero if an error occurs.

Definition at line 125 of file Sd2Card.cpp.

uint8_t Sd2Card::erase ( uint32_t  firstBlock,
uint32_t  lastBlock 
)

Erase a range of blocks.

Parameters:
[in]firstBlockThe address of the first block in the range.
[in]lastBlockThe address of the last block in the range.
Note:
This function requests the SD card to do a flash erase for a range of blocks. The data on the card after an erase operation is either 0 or 1, depends on the card vendor. The card must support single block erase.
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure.

Definition at line 166 of file Sd2Card.cpp.

uint8_t Sd2Card::eraseSingleBlockEnable ( void  )

Determine if card supports single block erase.

Returns:
The value one, true, is returned if single block erase is supported. The value zero, false, is returned if single block erase is not supported.

Definition at line 198 of file Sd2Card.cpp.

uint8_t Sd2Card::errorCode ( void  ) const [inline]
Returns:
error code for last error. See Sd2Card.h for a list of error codes.

Definition at line 162 of file Sd2Card.h.

uint8_t Sd2Card::errorData ( void  ) const [inline]
Returns:
error data for last error.

Definition at line 164 of file Sd2Card.h.

uint8_t Sd2Card::init ( uint8_t  sckRateID,
uint8_t  chipSelectPin 
)

Initialize an SD flash memory card.

Parameters:
[in]sckRateIDSPI clock rate selector. See setSckRate().
[in]chipSelectPinSD chip select pin number.
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure. The reason for failure can be determined by calling errorCode() and errorData().

Definition at line 213 of file Sd2Card.cpp.

uint8_t Sd2Card::init ( void  ) [inline]

Initialize an SD flash memory card with default clock rate and chip select pin.

See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).

Definition at line 169 of file Sd2Card.h.

uint8_t Sd2Card::init ( uint8_t  sckRateID) [inline]

Initialize an SD flash memory card with the selected SPI clock rate and the default SD chip select pin.

See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin).

Definition at line 177 of file Sd2Card.h.

void Sd2Card::partialBlockRead ( uint8_t  value)

Enable or disable partial block reads.

Enabling partial block reads improves performance by allowing a block to be read over the SPI bus as several sub-blocks. Errors may occur if the time between reads is too long since the SD card may timeout. The SPI SS line will be held low until the entire block is read or readEnd() is called.

Use this for applications like the Adafruit Wave Shield.

Parameters:
[in]valueThe value TRUE (non-zero) or FALSE (zero).)

Definition at line 307 of file Sd2Card.cpp.

uint8_t Sd2Card::partialBlockRead ( void  ) const [inline]

Returns the current value, true or false, for partial block read.

Definition at line 183 of file Sd2Card.h.

uint8_t Sd2Card::readBlock ( uint32_t  block,
uint8_t *  dst 
)

Read a 512 byte block from an SD card device.

Parameters:
[in]blockLogical block to be read.
[out]dstPointer to the location that will receive the data.
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure.

Definition at line 321 of file Sd2Card.cpp.

uint8_t Sd2Card::readCID ( cid_t cid) [inline]

Read a cards CID register.

The CID contains card identification information such as Manufacturer ID, Product name, Product serial number and Manufacturing date.

Definition at line 191 of file Sd2Card.h.

uint8_t Sd2Card::readCSD ( csd_t csd) [inline]

Read a cards CSD register.

The CSD contains Card-Specific Data that provides information regarding access to the card's contents.

Definition at line 197 of file Sd2Card.h.

uint8_t Sd2Card::readData ( uint32_t  block,
uint16_t  offset,
uint16_t  count,
uint8_t *  dst 
)

Read part of a 512 byte block from an SD card.

Parameters:
[in]blockLogical block to be read.
[in]offsetNumber of bytes to skip at start of block
[out]dstPointer to the location that will receive the data.
[in]countNumber of bytes to read
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure.

Definition at line 335 of file Sd2Card.cpp.

void Sd2Card::readEnd ( void  )

Skip remaining data in a block when in partial block read mode.

Definition at line 402 of file Sd2Card.cpp.

uint8_t Sd2Card::setSckRate ( uint8_t  sckRateID)

Set the SPI clock rate.

Parameters:
[in]sckRateIDA value in the range [0, 6].

The SPI clock will be set to F_CPU/pow(2, 1 + sckRateID). The maximum SPI rate is F_CPU/2 for sckRateID = 0 and the minimum rate is F_CPU/128 for scsRateID = 6.

Returns:
The value one, true, is returned for success and the value zero, false, is returned for an invalid value of sckRateID.

Definition at line 454 of file Sd2Card.cpp.

uint8_t Sd2Card::writeBlock ( uint32_t  blockNumber,
const uint8_t *  src 
)

Writes a 512 byte block to an SD card.

Parameters:
[in]blockNumberLogical block to be written.
[in]srcPointer to the location of the data to be written.
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure.

Definition at line 509 of file Sd2Card.cpp.

uint8_t Sd2Card::writeStart ( uint32_t  blockNumber,
uint32_t  eraseCount 
)

Start a write multiple blocks sequence.

Parameters:
[in]blockNumberAddress of first block in sequence.
[in]eraseCountThe number of blocks to be pre-erased.
Note:
This function is used with writeData() and writeStop() for optimized multiple block writes.
Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure.

Definition at line 602 of file Sd2Card.cpp.

uint8_t Sd2Card::writeStop ( void  )

End a write multiple blocks sequence.

Returns:
The value one, true, is returned for success and the value zero, false, is returned for failure.

Definition at line 633 of file Sd2Card.cpp.


The documentation for this class was generated from the following files: