This example demonstrates the reading of the SD card in the Nucleo.

Dependencies:   SDFileSystem mbed

Intro

This example demonstrates the reading of the SD card in the Nucleo.

Parts

STM32 Nucleo F446RE
QVGA 2.2 TFT SPI (with the SD card slot)
Breadboard
Wires

Wiring diagram

/media/uploads/beaglescout007/nucleo_ex05_sd.png This circuit diagram was created by fritzing.

/media/uploads/beaglescout007/tft_back.jpg

TFT J4Nucleo
SD_CSPA_9
SD_MOSIPB_15
SD_MISOPB_14
SD_SCKPB_13

https://youtu.be/nBRZO8_q78I

Used Library

Import librarySDFileSystem

A re-written SDFileSystem library with improved compatibility, CRC support, and card removal/replacement support.

Files at this revision

API Documentation at this revision

Comitter:
beaglescout007
Date:
Mon Mar 21 08:58:22 2016 +0000
Commit message:
Release

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b0a3ecd53c7d SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Mon Mar 21 08:58:22 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/neilt6/code/SDFileSystem/#3fa5eaf48e81
diff -r 000000000000 -r b0a3ecd53c7d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 21 08:58:22 2016 +0000
@@ -0,0 +1,46 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+
+DigitalIn btn(USER_BUTTON);
+
+// trim '\n'
+void ntrim(char *str)
+{
+    int i;
+    for (i = 0; str[i] != 0; ++i);
+
+    if (i > 0 && str[i - 1] == '\n')
+        str[i - 1] = 0;
+}
+
+int main()
+{
+    // SD filesystem
+    SDFileSystem *sd = new SDFileSystem(PB_15, PB_14, PB_13, PA_9, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, name, card detect, sw type, freq
+
+    while (1)
+    {
+        if (btn) continue;
+
+        // file open
+        FILE *fp = fopen("/sd/test.txt", "r");
+        if (fp == NULL)
+        {
+            printf("open error!!\r\n");
+            while(1);
+        }
+        
+        // read text file
+        char buf[1024];
+        while (fgets(buf, sizeof(buf), fp) != NULL)
+        {
+            ntrim(buf);            
+            printf("%s\r\n", buf);
+        }
+    
+        // file close
+        fclose(fp);        
+
+        wait(1);
+    }
+}
diff -r 000000000000 -r b0a3ecd53c7d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 21 08:58:22 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/c0f6e94411f5
\ No newline at end of file