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.
9 years, 5 months ago. This question has been closed. Reason: Duplicate question
Problem with SDcard
Hi I want to write some data in SDcard but led2 didn't turn on I try the Mbed SDFileSystem main program and it works so my device is ok
Can anyone help me ? Thanks
Edit : I created a new topic on Mbed forum
include the mbed library with this snippet
#include "mbed.h"
#include "SDFileSystem.h"
SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
AnalogIn capteur(p18);//Lecture de la valeur en sortie de l'ADC
InterruptIn boutonStop(p20);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
Timer tot;
Timer t;
Timeout appel;
float b;
int d,e;
float buffer_chiffre[2][400];
int indiceBuffer = 0;
float seuilHaut = 0.564;
float seuilBas = 0.558;
void Stop()
{
led1=0;
led2=1;
led3=0;
led4=0;
exit(0);
}
void flip() {
e = 1;
}
int main()
{
boutonStop.fall(&Stop);
led1=1;
mkdir("/sd/mydir", 0777);
FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
if(fp == NULL)
{
error("Could not open file for write\n");
}
fprintf(fp, "temps;a;\r\n");
led2 = 1;
led2 = 0;
led1=0;
d = 1;
while (d == 1)
{
tot.start();
t.start();
b=capteur.read();
if (b>seuilHaut || 1-b>seuilBas)//On pose une limite arbitraire qui est 0.57
{
led1=1;
e = 0;
buffer_chiffre[0][0] = tot.read();
buffer_chiffre[1][0] = capteur.read();
appel.attach_us(&flip, 1000);
while (e!=1)//On fait durer l'acquisition xs après le premier impact pour visualiser la courbe si ADC assez rapide
{
indiceBuffer=indiceBuffer+1;
buffer_chiffre[0][indiceBuffer] = tot.read();
buffer_chiffre[1][indiceBuffer] = capteur.read();
}led1=0;
}
if (buffer_chiffre[1][indiceBuffer] != 0)
{
for (int k = 0; k < 10; k++)
{
led3=1;
fprintf(fp,"%f;", buffer_chiffre[0][k]);
led3=0;
led4=1;
fprintf(fp,"%f;\r\n", buffer_chiffre[1][k]);
led4=0;
indiceBuffer = 0;
}
t.stop();
t.reset();
}
}
fclose(fp);
}