Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hello i'm trying to write on a sd card with the SDFileSystem library of Neil Thiessen but i receive always "writing and reading to sd card failed "
i've connected the Mosi with D11 , SCK with D13, Miso with D12 and CS with D4 and of course the pin 3 and 6 of the sd card to gnd and the pin 4 of the sd card to 3.3v i've tested some sd 128mb, 16gb and 4 gb but without success. do you have any idea/suggestion ? Thank you very much
sd card
#include "mbed.h" #include "SDFileSystem.h" //Create an SDFileSystem object SDFileSystem sd(D11, D12, D13, D4, "sd"); Serial pc(USBTX,USBRX); int main() { wait(1); //Mount the filesystem sd.mount(); pc.baud(115200); wait(1); //Perform a write test pc.printf("\n\rWriiting to SD card..."); FILE *fp = fopen("/sd/sdtest.txt", "w"); if (fp != NULL) { fprintf(fp, "We're writing to an SD card!"); fclose(fp); pc.printf("success!\n\r"); } else { pc.printf("failed!\n"); } //Perform a read test pc.printf("Reading from SD card..."); fp = fopen("/sd/sdtest.txt", "r"); if (fp != NULL) { char c = fgetc(fp); if (c == 'W') pc.printf("success!\n"); else pc.printf("incorrect char (%c)!\n", c); fclose(fp); } else { pc.printf("failed!\n"); } //Unmount the filesystem sd.unmount(); }