Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Demo_NucleoF4xx_SD_Card by
main.cpp
00001 #include "mbed.h" 00002 #include "SDFileSystem.h" 00003 00004 SDFileSystem sd(D11, D12, D13, D10, "sd"); // MOSI, MISO, SCK, CS: SPI1 00005 //SDFileSystem sd(D4, D5, D3, D2, "sd"); // MOSI, MISO, SCK, CS: SPI3 00006 //原平台LPC1768 (p11, p12, p13, p8, "sd"); 00007 // mosi,miso,sck,cs, 00008 // nucleo D11,D12,D13,D10 00009 00010 Serial pc_(USBTX, USBRX); 00011 00012 int main() { 00013 pc_.baud(115200); 00014 pc_.printf("\r\nInitializing\r\n"); 00015 00016 // 書き込みのテスト == Test writing 00017 pc_.printf("\nWriting to SD card...: "); 00018 //mkdir("/sd/mydir", 0777); //criar uma pasta 00019 //FILE *fp = fopen("/sd/mydir/sdtest.txt", "a");//"w" para criar o ficheiro limpo, "a" para append (adicionar ao ficheiro) 00020 FILE *fp = fopen("/sd/sdtest.txt", "a+"); // additional writing 00021 00022 if (fp != NULL) 00023 { 00024 fprintf(fp, "SD sdsdsd"); //texto a escrever no ficheiro 00025 fclose(fp); 00026 pc_.printf("success!\r\n"); 00027 } 00028 else 00029 pc_.printf("failed!\r\n"); 00030 00031 // 読み出しのテスト == Test readout 00032 pc_.printf("Reading from SD card...:\r\n"); 00033 fp = fopen("/sd/sdtest.txt", "r"); 00034 if (fp != NULL) 00035 { 00036 char str[256]; 00037 while (fgets(str, 256, fp) != NULL) 00038 pc_.printf("%s", str); 00039 00040 fclose(fp); 00041 pc_.printf("\r\nsuccess!\r\n"); 00042 } 00043 else 00044 pc_.printf("failed!\r\n"); 00045 00046 while (true) {} 00047 }
Generated on Tue Jul 12 2022 18:58:49 by
1.7.2
