Amundson OCE 360 homework 7 SD card library
Fork of SDFileSystem by
Revision 25:923df4ee70c4, committed 2016-05-26
- Comitter:
- neilt6
- Date:
- Thu May 26 15:32:31 2016 +0000
- Parent:
- 24:a52e682a1ce4
- Child:
- 26:e4d2567200db
- Commit message:
- Improved card initialization reliability
Changed in this revision
SDFileSystem.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/SDFileSystem.cpp Tue May 24 15:50:26 2016 +0000 +++ b/SDFileSystem.cpp Thu May 26 15:32:31 2016 +0000 @@ -163,13 +163,23 @@ //Set the SPI frequency to 400kHz for initialization m_Spi.frequency(400000); - //Send 80 dummy clocks with /CS deasserted and DI held high - m_Cs = 1; - for (int i = 0; i < 10; i++) - m_Spi.write(0xFF); + //Try to reset the card up to 3 times + for (int f = 0; f < 3; f++) { + //Send 80 dummy clocks with /CS deasserted and DI held high + m_Cs = 1; + for (int i = 0; i < 10; i++) { + m_Spi.write(0xFF); + } - //Send CMD0(0x00000000) to reset the card - if (commandTransaction(CMD0, 0x00000000) != 0x01) { + //Send CMD0(0x00000000) to reset the card + token = commandTransaction(CMD0, 0x00000000); + if (token == 0x01) { + break; + } + } + + //Check if the card reset + if (token != 0x01) { //Initialization failed m_CardType = CARD_UNKNOWN; return m_Status;