Soldered SD Card Arduino Library 1.0.0
Easily read and write files to and form the SD card breakout! A fork of the original SDFat library by Bill Greiman.
Loading...
Searching...
No Matches
SdCardInfo.h File Reference

Go to the source code of this file.

Classes

class  CID
 Card IDentification (CID) register. More...
 
class  CSDV1
 CSD register for version 1.00 cards . More...
 
class  CSDV2
 CSD register for version 2.00 cards. More...
 
class  csd_t
 Union of old and new style CSD register. More...
 
struct  SdStatus
 

Typedefs

typedef struct SdStatus SdStatus_t
 

Enumerations

enum  { SD_CARD_ERROR_UNKNOWN }
 

Functions

void printSdErrorSymbol (print_t *pr, uint8_t code)
 
void printSdErrorText (print_t *pr, uint8_t code)
 
struct CID __attribute__ ((packed)) cid_t
 
uint32_t sdCardCapacity (csd_t *csd)
 

Variables

const uint8_t SD_CARD_TYPE_SD1 = 1
 
const uint8_t SD_CARD_TYPE_SD2 = 2
 
const uint8_t SD_CARD_TYPE_SDHC = 3
 
const uint8_t SD_CMD0_RETRY = 10
 
const uint16_t SD_CMD_TIMEOUT = 300
 
const uint16_t SD_ERASE_TIMEOUT = 10000
 
const uint16_t SD_INIT_TIMEOUT = 2000
 
const uint16_t SD_READ_TIMEOUT = 300
 
const uint16_t SD_WRITE_TIMEOUT = 600
 
const uint8_t CMD0 = 0X00
 
const uint8_t CMD2 = 0X02
 
const uint8_t CMD3 = 0X03
 
const uint8_t CMD6 = 0X06
 
const uint8_t CMD7 = 0X07
 
const uint8_t CMD8 = 0X08
 
const uint8_t CMD9 = 0X09
 
const uint8_t CMD10 = 0X0A
 
const uint8_t CMD11 = 0X0B
 
const uint8_t CMD12 = 0X0C
 
const uint8_t CMD13 = 0X0D
 
const uint8_t CMD17 = 0X11
 
const uint8_t CMD18 = 0X12
 
const uint8_t CMD24 = 0X18
 
const uint8_t CMD25 = 0X19
 
const uint8_t CMD32 = 0X20
 
const uint8_t CMD33 = 0X21
 
const uint8_t CMD38 = 0X26
 
const uint8_t CMD55 = 0X37
 
const uint8_t CMD58 = 0X3A
 
const uint8_t CMD59 = 0X3B
 
const uint8_t ACMD6 = 0X06
 
const uint8_t ACMD13 = 0X0D
 
const uint8_t ACMD23 = 0X17
 
const uint8_t ACMD41 = 0X29
 
const uint32_t CARD_STATUS_OUT_OF_RANGE = 1UL << 31
 
const uint32_t CARD_STATUS_ADDRESS_ERROR = 1UL << 30
 
const uint32_t CARD_STATUS_SECTOR_LEN_ERROR = 1UL << 29
 
const uint32_t CARD_STATUS_ERASE_SEQ_ERROR = 1UL << 28
 
const uint32_t CARD_STATUS_ERASE_PARAM = 1UL << 27
 
const uint32_t CARD_STATUS_WP_VIOLATION = 1UL << 26
 
const uint32_t CARD_STATUS_CARD_IS_LOCKED = 1UL << 25
 
const uint32_t CARD_STATUS_LOCK_UNLOCK_FAILED = 1UL << 24
 
const uint32_t CARD_STATUS_COM_CRC_ERROR = 1UL << 23
 
const uint32_t CARD_STATUS_ILLEGAL_COMMAND = 1UL << 22
 
const uint32_t CARD_STATUS_CARD_ECC_FAILED = 1UL << 21
 
const uint32_t CARD_STATUS_CC_ERROR = 1UL << 20
 
const uint32_t CARD_STATUS_ERROR = 1UL << 19
 
const uint32_t CARD_STATUS_CSD_OVERWRITE = 1UL << 16
 
const uint32_t CARD_STATUS_WP_ERASE_SKIP = 1UL << 15
 
const uint32_t CARD_STATUS_CARD_ECC_DISABLED = 1UL << 14
 
const uint32_t CARD_STATUS_ERASE_RESET = 1UL << 13
 
const uint32_t CARD_STATUS_CURRENT_STATE = 0XF << 9
 
const uint32_t CARD_STATUS_CURRENT_STATE_SHIFT = 9
 
const uint32_t CARD_STATUS_READY_FOR_DATA = 1UL << 8
 
const uint32_t CARD_STATUS_FX_EVENT = 1UL << 6
 
const uint32_t CARD_STATUS_APP_CMD = 1UL << 5
 
const uint32_t CARD_STATUS_AKE_SEQ_ERROR = 1UL << 3
 
const uint8_t R1_READY_STATE = 0X00
 
const uint8_t R1_IDLE_STATE = 0X01
 
const uint8_t R1_ILLEGAL_COMMAND = 0X04
 
const uint8_t DATA_START_SECTOR = 0XFE
 
const uint8_t STOP_TRAN_TOKEN = 0XFD
 
const uint8_t WRITE_MULTIPLE_TOKEN = 0XFC
 
const uint8_t DATA_RES_MASK = 0X1F
 
const uint8_t DATA_RES_ACCEPTED = 0X05
 
unsigned char mid
 
char oid [2]
 
char pnm [5]
 
unsigned char prv_m
 
unsigned char prv_n
 
uint32_t psn
 
unsigned char mdt_year_high
 
unsigned char reserved
 
unsigned char mdt_month
 
unsigned char mdt_year_low
 
unsigned char always1
 
unsigned char crc
 
unsigned char reserved1
 
unsigned char csd_ver
 
unsigned char taac
 
unsigned char nsac
 
unsigned char tran_speed
 
unsigned char ccc_high
 
unsigned char read_bl_len
 
unsigned char ccc_low
 
unsigned char c_size_high
 
unsigned char reserved2
 
unsigned char dsr_imp
 
unsigned char read_blk_misalign
 
unsigned char write_blk_misalign
 
unsigned char read_bl_partial
 
unsigned char c_size_mid
 
unsigned char vdd_r_curr_max
 
unsigned char vdd_r_curr_min
 
unsigned char c_size_low
 
unsigned char c_size_mult_high
 
unsigned char vdd_w_cur_max
 
unsigned char vdd_w_curr_min
 
unsigned char sector_size_high
 
unsigned char erase_blk_en
 
unsigned char c_size_mult_low
 
unsigned char wp_grp_size
 
unsigned char sector_size_low
 
unsigned char write_bl_len_high
 
unsigned char r2w_factor
 
unsigned char reserved3
 
unsigned char wp_grp_enable
 
unsigned char reserved4
 
unsigned char write_partial
 
unsigned char write_bl_len_low
 
unsigned char reserved5
 
unsigned char file_format
 
unsigned char tmp_write_protect
 
unsigned char perm_write_protect
 
unsigned char copy
 
unsigned char file_format_grp
 
unsigned char reserved6
 
unsigned char reserved7
 
union csd_t __attribute__
 

Typedef Documentation

◆ SdStatus_t

typedef struct SdStatus SdStatus_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SD_CARD_ERROR_UNKNOWN 

Function Documentation

◆ __attribute__()

struct CID __attribute__ ( (packed)  )

◆ printSdErrorSymbol()

void printSdErrorSymbol ( print_t pr,
uint8_t  code 
)

◆ printSdErrorText()

void printSdErrorText ( print_t pr,
uint8_t  code 
)

◆ sdCardCapacity()

uint32_t sdCardCapacity ( csd_t csd)
inline

Variable Documentation

◆ __attribute__

__attribute__

◆ ACMD13

const uint8_t ACMD13 = 0X0D

SD_STATUS - Send the SD Status.

◆ ACMD23

const uint8_t ACMD23 = 0X17

SET_WR_BLK_ERASE_COUNT - Set the number of write sectors to be pre-erased before writing

◆ ACMD41

const uint8_t ACMD41 = 0X29

SD_SEND_OP_COMD - Sends host capacity support information and activates the card's initialization process

◆ ACMD6

const uint8_t ACMD6 = 0X06

SET_BUS_WIDTH - Defines the data bus width for data transfer.

◆ always1

unsigned char always1

not used always 1

◆ c_size_high

unsigned char c_size_high

high part of card size

◆ c_size_low

unsigned char c_size_low

low part of card size

◆ c_size_mid

unsigned char c_size_mid

middle part of card size

◆ c_size_mult_high

unsigned char c_size_mult_high

◆ c_size_mult_low

unsigned char c_size_mult_low

◆ CARD_STATUS_ADDRESS_ERROR

const uint32_t CARD_STATUS_ADDRESS_ERROR = 1UL << 30

A misaligned address which did not match the sector length.

◆ CARD_STATUS_AKE_SEQ_ERROR

const uint32_t CARD_STATUS_AKE_SEQ_ERROR = 1UL << 3

Error in the sequence of the authentication process.

◆ CARD_STATUS_APP_CMD

const uint32_t CARD_STATUS_APP_CMD = 1UL << 5

The card will expect ACMD, or the command has been interpreted as ACMD

◆ CARD_STATUS_CARD_ECC_DISABLED

const uint32_t CARD_STATUS_CARD_ECC_DISABLED = 1UL << 14

The command has been executed without using the internal ECC.

◆ CARD_STATUS_CARD_ECC_FAILED

const uint32_t CARD_STATUS_CARD_ECC_FAILED = 1UL << 21

Card internal ECC was applied but failed to correct the data.

◆ CARD_STATUS_CARD_IS_LOCKED

const uint32_t CARD_STATUS_CARD_IS_LOCKED = 1UL << 25

When set, signals that the card is locked by the host.

◆ CARD_STATUS_CC_ERROR

const uint32_t CARD_STATUS_CC_ERROR = 1UL << 20

Internal card controller error

◆ CARD_STATUS_COM_CRC_ERROR

const uint32_t CARD_STATUS_COM_CRC_ERROR = 1UL << 23

The CRC check of the previous command failed.

◆ CARD_STATUS_CSD_OVERWRITE

const uint32_t CARD_STATUS_CSD_OVERWRITE = 1UL << 16

Permanent WP set or attempt to change read only values of CSD.

◆ CARD_STATUS_CURRENT_STATE

const uint32_t CARD_STATUS_CURRENT_STATE = 0XF << 9

The state of the card when receiving the command. 0 = idle 1 = ready 2 = ident 3 = stby 4 = tran 5 = data 6 = rcv 7 = prg 8 = dis 9-14 = reserved 15 = reserved for I/O mode

◆ CARD_STATUS_CURRENT_STATE_SHIFT

const uint32_t CARD_STATUS_CURRENT_STATE_SHIFT = 9

Shift for current state.

◆ CARD_STATUS_ERASE_PARAM

const uint32_t CARD_STATUS_ERASE_PARAM = 1UL << 27

An invalid selection of write-sectors for erase occurred.

◆ CARD_STATUS_ERASE_RESET

const uint32_t CARD_STATUS_ERASE_RESET = 1UL << 13

out of erase sequence command was received.

◆ CARD_STATUS_ERASE_SEQ_ERROR

const uint32_t CARD_STATUS_ERASE_SEQ_ERROR = 1UL << 28

An error in the sequence of erase commands occurred.

◆ CARD_STATUS_ERROR

const uint32_t CARD_STATUS_ERROR = 1UL << 19

A general or an unknown error occurred during the operation.

◆ CARD_STATUS_FX_EVENT

const uint32_t CARD_STATUS_FX_EVENT = 1UL << 6

Extension Functions may set this bit to get host to deal with events.

◆ CARD_STATUS_ILLEGAL_COMMAND

const uint32_t CARD_STATUS_ILLEGAL_COMMAND = 1UL << 22

Command not legal for the card state.

◆ CARD_STATUS_LOCK_UNLOCK_FAILED

const uint32_t CARD_STATUS_LOCK_UNLOCK_FAILED = 1UL << 24

Set when a sequence or password error has been detected.

◆ CARD_STATUS_OUT_OF_RANGE

const uint32_t CARD_STATUS_OUT_OF_RANGE = 1UL << 31

The command's argument was out of the allowed range for this card.

◆ CARD_STATUS_READY_FOR_DATA

const uint32_t CARD_STATUS_READY_FOR_DATA = 1UL << 8

Corresponds to buffer empty signaling on the bus.

◆ CARD_STATUS_SECTOR_LEN_ERROR

const uint32_t CARD_STATUS_SECTOR_LEN_ERROR = 1UL << 29

The transferred sector length is not allowed for this card.

◆ CARD_STATUS_WP_ERASE_SKIP

const uint32_t CARD_STATUS_WP_ERASE_SKIP = 1UL << 15

partial address space was erased due to write protect.

◆ CARD_STATUS_WP_VIOLATION

const uint32_t CARD_STATUS_WP_VIOLATION = 1UL << 26

Set when the host attempts to write to a protected sector.

◆ ccc_high

unsigned char ccc_high

◆ ccc_low

unsigned char ccc_low

◆ CMD0

const uint8_t CMD0 = 0X00

GO_IDLE_STATE - init card in spi mode if CS low

◆ CMD10

const uint8_t CMD10 = 0X0A

SEND_CID - read the card identification information (CID register)

◆ CMD11

const uint8_t CMD11 = 0X0B

VOLTAGE_SWITCH -Switch to 1.8V bus signaling level.

◆ CMD12

const uint8_t CMD12 = 0X0C

STOP_TRANSMISSION - end multiple sector read sequence

◆ CMD13

const uint8_t CMD13 = 0X0D

SEND_STATUS - read the card status register

◆ CMD17

const uint8_t CMD17 = 0X11

READ_SINGLE_SECTOR - read a single data sector from the card

◆ CMD18

const uint8_t CMD18 = 0X12

READ_MULTIPLE_SECTOR - read multiple data sectors from the card

◆ CMD2

const uint8_t CMD2 = 0X02

ALL_SEND_CID - Asks any card to send the CID.

◆ CMD24

const uint8_t CMD24 = 0X18

WRITE_SECTOR - write a single data sector to the card

◆ CMD25

const uint8_t CMD25 = 0X19

WRITE_MULTIPLE_SECTOR - write sectors of data until a STOP_TRANSMISSION

◆ CMD3

const uint8_t CMD3 = 0X03

SEND_RELATIVE_ADDR - Ask the card to publish a new RCA.

◆ CMD32

const uint8_t CMD32 = 0X20

ERASE_WR_BLK_START - sets the address of the first sector to be erased

◆ CMD33

const uint8_t CMD33 = 0X21

ERASE_WR_BLK_END - sets the address of the last sector of the continuous range to be erased

◆ CMD38

const uint8_t CMD38 = 0X26

ERASE - erase all previously selected sectors

◆ CMD55

const uint8_t CMD55 = 0X37

APP_CMD - escape for application specific command

◆ CMD58

const uint8_t CMD58 = 0X3A

READ_OCR - read the OCR register of a card

◆ CMD59

const uint8_t CMD59 = 0X3B

CRC_ON_OFF - enable or disable CRC checking

◆ CMD6

const uint8_t CMD6 = 0X06

SWITCH_FUNC - Switch Function Command

◆ CMD7

const uint8_t CMD7 = 0X07

SELECT/DESELECT_CARD - toggles between the stand-by and transfer states.

◆ CMD8

const uint8_t CMD8 = 0X08

SEND_IF_COND - verify SD Memory Card interface operating condition.

◆ CMD9

const uint8_t CMD9 = 0X09

SEND_CSD - read the Card Specific Data (CSD register)

◆ copy

unsigned char copy

◆ crc

unsigned char crc

CRC7 checksum

checksum

◆ csd_ver

unsigned char csd_ver

◆ DATA_RES_ACCEPTED

const uint8_t DATA_RES_ACCEPTED = 0X05

write data accepted token

◆ DATA_RES_MASK

const uint8_t DATA_RES_MASK = 0X1F

mask for data response tokens after a write sector operation

◆ DATA_START_SECTOR

const uint8_t DATA_START_SECTOR = 0XFE

start data token for read or write single sector

◆ dsr_imp

unsigned char dsr_imp

◆ erase_blk_en

unsigned char erase_blk_en

fixed to 1 - erase single is supported

◆ file_format

unsigned char file_format

Do not use always 0

◆ file_format_grp

unsigned char file_format_grp

Indicates the file format on the card

Do not use always 0

◆ mdt_month

unsigned char mdt_month

Manufacturing date month

◆ mdt_year_high

unsigned char mdt_year_high

Manufacturing date year high digit

◆ mdt_year_low

unsigned char mdt_year_low

Manufacturing date year low digit

◆ mid

unsigned char mid

Manufacturer ID

◆ nsac

unsigned char nsac

fixed to 0

◆ oid

char oid[2]

OEM/Application ID

◆ perm_write_protect

unsigned char perm_write_protect

◆ pnm

char pnm[5]

Product name

◆ prv_m

unsigned char prv_m

Product revision least significant digit

◆ prv_n

unsigned char prv_n

Product revision most significant digit

◆ psn

uint32_t psn

Product serial number

◆ R1_IDLE_STATE

const uint8_t R1_IDLE_STATE = 0X01

status for card in the idle state

◆ R1_ILLEGAL_COMMAND

const uint8_t R1_ILLEGAL_COMMAND = 0X04

status bit for illegal command

◆ R1_READY_STATE

const uint8_t R1_READY_STATE = 0X00

status for card in the ready state

◆ r2w_factor

unsigned char r2w_factor

fixed value of 2

◆ read_bl_len

unsigned char read_bl_len

This field is fixed to 9h, which indicates READ_BL_LEN=512 Byte

◆ read_bl_partial

unsigned char read_bl_partial

fixed to 0 - no partial read

◆ read_blk_misalign

unsigned char read_blk_misalign

fixed to 0

◆ reserved

unsigned char reserved

not used

◆ reserved1

unsigned char reserved1

◆ reserved2

unsigned char reserved2

not used

◆ reserved3

unsigned char reserved3

not used

◆ reserved4

unsigned char reserved4

not used

◆ reserved5

unsigned char reserved5

not used

◆ reserved6

unsigned char reserved6

◆ reserved7

unsigned char reserved7

◆ SD_CARD_TYPE_SD1

const uint8_t SD_CARD_TYPE_SD1 = 1

Standard capacity V1 SD card

◆ SD_CARD_TYPE_SD2

const uint8_t SD_CARD_TYPE_SD2 = 2

Standard capacity V2 SD card

◆ SD_CARD_TYPE_SDHC

const uint8_t SD_CARD_TYPE_SDHC = 3

High Capacity SD card

◆ SD_CMD0_RETRY

const uint8_t SD_CMD0_RETRY = 10

CMD0 retry count

◆ SD_CMD_TIMEOUT

const uint16_t SD_CMD_TIMEOUT = 300

command timeout ms

◆ SD_ERASE_TIMEOUT

const uint16_t SD_ERASE_TIMEOUT = 10000

erase timeout ms

◆ SD_INIT_TIMEOUT

const uint16_t SD_INIT_TIMEOUT = 2000

init timeout ms

◆ SD_READ_TIMEOUT

const uint16_t SD_READ_TIMEOUT = 300

read timeout ms

◆ SD_WRITE_TIMEOUT

const uint16_t SD_WRITE_TIMEOUT = 600

write time out ms

◆ sector_size_high

unsigned char sector_size_high

sector size is fixed at 64 KB

◆ sector_size_low

unsigned char sector_size_low

sector size is fixed at 64 KB

◆ STOP_TRAN_TOKEN

const uint8_t STOP_TRAN_TOKEN = 0XFD

stop token for write multiple sectors

◆ taac

unsigned char taac

fixed to 0X0E

◆ tmp_write_protect

unsigned char tmp_write_protect

◆ tran_speed

unsigned char tran_speed

◆ vdd_r_curr_max

unsigned char vdd_r_curr_max

◆ vdd_r_curr_min

unsigned char vdd_r_curr_min

◆ vdd_w_cur_max

unsigned char vdd_w_cur_max

◆ vdd_w_curr_min

unsigned char vdd_w_curr_min

◆ wp_grp_enable

unsigned char wp_grp_enable

fixed value of 0 - no write protect groups

◆ wp_grp_size

unsigned char wp_grp_size

◆ write_bl_len_high

unsigned char write_bl_len_high

write_bl_len fixed for 512 byte sectors

◆ write_bl_len_low

unsigned char write_bl_len_low

write_bl_len fixed for 512 byte sectors

◆ write_blk_misalign

unsigned char write_blk_misalign

fixed to 0

◆ WRITE_MULTIPLE_TOKEN

const uint8_t WRITE_MULTIPLE_TOKEN = 0XFC

start data token for write multiple sectors

◆ write_partial

unsigned char write_partial

always zero - no partial sector read