Sd card

Dependencies:   mbed SDFileSystem

Committer:
mariangelamone
Date:
Fri Feb 04 14:33:57 2022 +0000
Revision:
3:f281a7095433
Parent:
2:8e4ad4ac6425
SD card per salvare su file compatibile con excel

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tubemerc 0:6337f8cfdd73 1 /*
tubemerc 2:8e4ad4ac6425 2 SDカードに整数を書き込む.
tubemerc 0:6337f8cfdd73 3 <pin接続>
tubemerc 0:6337f8cfdd73 4 NSS: pin25 --- pin2 CD/DAT3
tubemerc 0:6337f8cfdd73 5 SCK: pin26 --- pin5 CLK
tubemerc 0:6337f8cfdd73 6 MISO:pin27 --- pin7 DAT0
tubemerc 0:6337f8cfdd73 7 MOSI:pin28 --- pin3 CMD
tubemerc 0:6337f8cfdd73 8 */
tubemerc 0:6337f8cfdd73 9 #include "mbed.h"
tubemerc 0:6337f8cfdd73 10 #include "SDFileSystem.h"
tubemerc 0:6337f8cfdd73 11
tubemerc 2:8e4ad4ac6425 12 DigitalOut myled(PB_1); //pin15
mariangelamone 3:f281a7095433 13 Serial pc(SERIAL_TX, SERIAL_RX);
tubemerc 0:6337f8cfdd73 14
tubemerc 2:8e4ad4ac6425 15 SDFileSystem sd = SDFileSystem(PB_5, PB_4, PB_3, PA_15, "sd"); //pin28,27,26,25
tubemerc 0:6337f8cfdd73 16
tubemerc 0:6337f8cfdd73 17 int main(){
tubemerc 0:6337f8cfdd73 18 wait(1.0); //気持ち
tubemerc 0:6337f8cfdd73 19 pc.printf("Start.\n\r");
tubemerc 0:6337f8cfdd73 20
tubemerc 0:6337f8cfdd73 21 FILE *fp = fopen("/sd/test.csv", "w");
tubemerc 0:6337f8cfdd73 22 //FILE *fp = fopen("/sd/test.txt", "w");
tubemerc 0:6337f8cfdd73 23 if(fp != NULL){
tubemerc 2:8e4ad4ac6425 24 myled = 1;
tubemerc 0:6337f8cfdd73 25 pc.printf("Writing to SDcard......\n\r");
tubemerc 0:6337f8cfdd73 26 for(int i=1;i<10;i++){
tubemerc 0:6337f8cfdd73 27 fprintf(fp, "%d\n", i);
tubemerc 0:6337f8cfdd73 28 }
tubemerc 0:6337f8cfdd73 29 fclose(fp);
tubemerc 2:8e4ad4ac6425 30 myled = 0;
tubemerc 0:6337f8cfdd73 31 }
tubemerc 0:6337f8cfdd73 32 else{
tubemerc 0:6337f8cfdd73 33 pc.printf("Failed.\n\r");
tubemerc 0:6337f8cfdd73 34 }
tubemerc 0:6337f8cfdd73 35 pc.printf("End.\n\r");
tubemerc 0:6337f8cfdd73 36 }