Gestione accelerometro e scrittura su SD da F4

Dependencies:   SDFileSystem1 mbed

Fork of SDFileSystem_HelloWorld by mbed official

Committer:
NdA994
Date:
Mon Nov 20 22:18:10 2017 +0000
Revision:
2:f59bd5312559
Libreria per scrittura su Sd completa. Ho eseguito dei test per vedere se l'accelerometro reggeva la scrittura ed hanno dato esiti positivi.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NdA994 2:f59bd5312559 1 #ifndef __LETTORESD__
NdA994 2:f59bd5312559 2 #define __LETTORESD__
NdA994 2:f59bd5312559 3
NdA994 2:f59bd5312559 4 #include "SDFileSystem.h"
NdA994 2:f59bd5312559 5
NdA994 2:f59bd5312559 6 int nFile = 1;
NdA994 2:f59bd5312559 7
NdA994 2:f59bd5312559 8 SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, A2, "sd");
NdA994 2:f59bd5312559 9 FILE *fp;
NdA994 2:f59bd5312559 10 char buffer[4100];
NdA994 2:f59bd5312559 11 int nCounter = 0;
NdA994 2:f59bd5312559 12
NdA994 2:f59bd5312559 13 void initFile(){
NdA994 2:f59bd5312559 14 mkdir("/sd/mydir", 0777);
NdA994 2:f59bd5312559 15 }
NdA994 2:f59bd5312559 16
NdA994 2:f59bd5312559 17
NdA994 2:f59bd5312559 18 FILE * aperturaFile(){
NdA994 2:f59bd5312559 19 char destinazione[14];
NdA994 2:f59bd5312559 20 char path[21]="/sd/mydir/";
NdA994 2:f59bd5312559 21 sprintf(destinazione, "%d", nFile);
NdA994 2:f59bd5312559 22 strcat(destinazione, ".txt");
NdA994 2:f59bd5312559 23 strcat(path, destinazione);
NdA994 2:f59bd5312559 24 fp = fopen(path, "w");
NdA994 2:f59bd5312559 25 if(fp == NULL){
NdA994 2:f59bd5312559 26 error("Could not open file for write\n");
NdA994 2:f59bd5312559 27 }
NdA994 2:f59bd5312559 28 return fp;
NdA994 2:f59bd5312559 29 }
NdA994 2:f59bd5312559 30
NdA994 2:f59bd5312559 31 void chiusuraFile(){
NdA994 2:f59bd5312559 32 fclose(fp);
NdA994 2:f59bd5312559 33 nFile++;
NdA994 2:f59bd5312559 34 buffer[0] = 0;
NdA994 2:f59bd5312559 35 nCounter = 0;
NdA994 2:f59bd5312559 36 }
NdA994 2:f59bd5312559 37
NdA994 2:f59bd5312559 38 void stampaFile(char* stringa){
NdA994 2:f59bd5312559 39 if(nCounter == 99){
NdA994 2:f59bd5312559 40 fprintf(fp, "%s", buffer);
NdA994 2:f59bd5312559 41 nCounter = 0;
NdA994 2:f59bd5312559 42 buffer[0] = 0;
NdA994 2:f59bd5312559 43 printf("sono qua <---------\n\r");
NdA994 2:f59bd5312559 44 }
NdA994 2:f59bd5312559 45 else{
NdA994 2:f59bd5312559 46 printf("sono qua\n\r");
NdA994 2:f59bd5312559 47 nCounter++;
NdA994 2:f59bd5312559 48 strcat(buffer, stringa);
NdA994 2:f59bd5312559 49 }
NdA994 2:f59bd5312559 50 }
NdA994 2:f59bd5312559 51
NdA994 2:f59bd5312559 52 #endif