Library for SD card
Dependents: SDFileSystem_HelloWorld Sharp_ce140f_emul
Revision 2:02f003d025a7, committed 2022-07-19
- Comitter:
- ffxx68
- Date:
- Tue Jul 19 13:49:28 2022 +0000
- Parent:
- 1:3488faedd0d1
- Commit message:
- SD Card handling added
Changed in this revision
| SDFileSystem.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/SDFileSystem.cpp Fri Jul 15 09:04:31 2022 +0000
+++ b/SDFileSystem.cpp Tue Jul 19 13:49:28 2022 +0000
@@ -151,10 +151,10 @@
#include "SDFileSystem.h"
#include "mbed_debug.h"
-#define SD_COMMAND_TIMEOUT 0x10/*5000*/
+#define SD_COMMAND_TIMEOUT 15/*5000*/
#define SD_CMD0_GO_IDLE_STATE_RETRIES 3
#define SD_CMD0_GO_IDLE_STATE 0x00
-#define SD_DBG 1
+#define SD_DBG 0
SDFileSystem::SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name) :
FATFileSystem(name), _spi(mosi, miso, sclk), _cs(cs), _is_initialized(0) {
@@ -200,8 +200,6 @@
int SDFileSystem::_go_idle_state() {
_spi.lock();
-
-
int cmd_arg = 0; /* CMD0 argument is just "stuff bits"*/
/* Resetting the MCU SPI master may not reset the on-board SDCard, in which
@@ -211,7 +209,7 @@
* the command overcomes this situation. */
for (int num_retries = 0; num_retries < SD_CMD0_GO_IDLE_STATE_RETRIES; num_retries++) {
- // Set to SCK for initialisation, and clock card with cs = 1
+ // Set to SCK for initialisation, and clock card with CS high
_cs = 1;
// Initial delay
wait_us (1000);
@@ -220,8 +218,9 @@
_spi.write(0xFF);
}
- /* send a CMD0, with /CS asserted */
+ /* send a CMD0, with /CS asserted low */
_cs = 0;
+ wait_us (1000);
_spi.write(0x40 | SD_CMD0_GO_IDLE_STATE);
_spi.write(cmd_arg >> 24);
_spi.write(cmd_arg >> 16);
@@ -242,7 +241,7 @@
_spi.unlock();
return response;
}
-
+ wait_us(1000);
}
}
_cs = 1;