I am doing a project with mbed using the library of SDCard.
What I am trying to do is to log the data into the SD card.
I have followed the instruction of SDCard library.
Firstly, connect the mbed with the SD socket as the following instruction.
MicroSD Breakout mbed
CS o-------------o 13 (DigitalOut cs)
DI o-------------o 5 (SPI mosi)
VCC o-------------o VOUT
SCK o-------------o 7 (SPI sclk)
GND o-------------o GND
DO o-------------o 6 (SPI miso)
CD o
Secondly, the cards were formatted using:
- Windows 7, Right-click, Format...
- Capacity: 59.4MB
- Filesystem: FAT (Default) [FAT, FAT32, NTFS, exFAT]
- Allocation size: 1024 bytes
Thirdly, import the FatFileSystem library and SDFileSystem code.
Lastly, change my code as follows:
#include "mbed.h"
#include "SDFileSystem.h"
AnalogIn xin(p20);
AnalogIn yin(p19);
SDFileSystem sd(p5, p6, p7, p13, "sd");
int main() {
float xval;
float yval;
int loop;
FILE *fp = fopen("/sd/foo.txt", "w");
if(fp == NULL) {
error("Could not open file for write\n");
}
while(1){
loop=loop+1;
xval=xin.read();
yval=yin.read();
fprintf(fp, "x: %f, y: %f\r\n", xval, yval);
if (loop>=10000) break;
}
fclose(fp);
} However, there is no any files when I plug the disk back in to my PC.
Could anyone help me to figure this out?
Secondly, the cards were formatted using:
Thirdly, import the FatFileSystem library and SDFileSystem code.
Lastly, change my code as follows:
#include "mbed.h" #include "SDFileSystem.h" AnalogIn xin(p20); AnalogIn yin(p19); SDFileSystem sd(p5, p6, p7, p13, "sd"); int main() { float xval; float yval; int loop; FILE *fp = fopen("/sd/foo.txt", "w"); if(fp == NULL) { error("Could not open file for write\n"); } while(1){ loop=loop+1; xval=xin.read(); yval=yin.read(); fprintf(fp, "x: %f, y: %f\r\n", xval, yval); if (loop>=10000) break; } fclose(fp); }However, there is no any files when I plug the disk back in to my PC.Could anyone help me to figure this out?