/* MSD chip select low */ MSD_CS_LOW(); /* Send CMD17 (MSD_READ_SINGLE_BLOCK) to read one block */ MSD_SendCmd(MSD_READ_SINGLE_BLOCK, ReadAddr, 0xFF);
/* Check if the MSD acknowledged the read block command: R1 response (0x00: no errors) */ if (!MSD_GetResponse(MSD_RESPONSE_NO_ERROR)) { /* Now look for the data token to signify the start of the data */ if (!MSD_GetResponse(MSD_START_DATA_SINGLE_BLOCK_READ)) { checksum = 0; /* Read the MSD block data : read NumByteToRead data */ for (i = 0; i < NumByteToRead; i++) { /* Save the received data */ *pBuffer = MSD_ReadByte(); checksum+=*pBuffer ; /* Point to the next location where the byte read will be saved */ pBuffer++; } /* Get CRC bytes (not really needed by us, but required by MSD) */ crc16=MSD_ReadByte(); crc16 = (crc16 <<8)|MSD_ReadByte(); /* Set response value to success */ rvalue = MSD_RESPONSE_NO_ERROR; } }
/* MSD chip select high */ MSD_CS_HIGH(); /* Send dummy byte: 8 Clock pulses of delay */ MSD_WriteByte(DUMMY); /* Returns the reponse */ return rvalue; }