SD Cards (Part 5)

Other posts on same subject Part 123456

Erratum!

While building a professional grade application I realized that I made a stupid mistake in the Blocks function from my PlainSDC library. Firstly, here is a nice table showing the content of the CARD SPECIFIC DATA REGISTER:

It is taken from the ‘APPLICATION NOTE 3969: SD Media Format Expands the MAXQ2000’s Space for Nonvolatile Data Storage’ edited by MAXIM DALLAS.

And now is the correct code

uint32_t PlainSDC::Blocks(void) 
/* Get nbr of blocks on SD memory card */
{
  uint8_t vBuffer[16];
	/* Read SD Card Size Details */
	ReadRegister(vBuffer, SDC_SEND_CSD); 
  /* Compute size */
	uint32_t C_Size = 0;
	C_Size |= ((vBuffer[6] & 0x03) << 10);
	C_Size |= ((vBuffer[7] & 0xFF) << 2);
	C_Size |= ((vBuffer[8] & 0xC0) >> 6);
	uint32_t C_Size_Mult = 0;
	C_Size_Mult |= ((vBuffer[9] & 0x03) << 1);
	C_Size_Mult |= ((vBuffer[10] & 0x80) >> 7);
  return ((C_Size + 1) << (C_Size_Mult + 2));
};

And a little compensation gift: an additional function which computes the size of the read blocks!

uint16_t PlainSDC::BlockSize(void) 
/* Get size of blocks on SD memory card */
{
  uint8_t vBuffer[16];
	/* Read SD Card Size Details */
	ReadRegister(vBuffer, SDC_SEND_CSD); 
  /* Compute size */
	uint16_t READ_BL_LEN = 0;
	READ_BL_LEN |= ((vBuffer[5] & 0x0F) );
  return (1 << READ_BL_LEN);
};

One Comment

  1. […] Next post on same subject Tags: SD Cards Comment (RSS)  |  Trackback […]

Leave a Reply

You must be logged in to post a comment.