hi,
recently i am trying to make a simply project that to store the analog data to sd card.
while reading the analog data on serial monitor there is no problem, the data shown perfectly.
but while add a SD card program, the analog read data on A0, A1 and A2 is set to zero, means that nothing is able to read by this analog input, and as for the A3 and A4 analog input is still able to read the data.
Here the program:
#include “mbed.h”
#include “SDFileSystem.h”
Serial pc(USBTX, USBRX);
SDFileSystem sd(D11, D12, D13, D9, “sd”); // the pinout on the mbed Cool Components workshop board //MOSI, MISO, SCLK, CS
DigitalIn eject (PA_12);
AnalogIn VBatt (PA_5); //battery voltage
AnalogIn VPvc (PA_4); //Photovoltaic cell voltage
float vbatt, vpvc;
AnalogIn APvc (PA_0); //Photovoltaic cell ampere
AnalogIn ABatt (PA_1); //Battery cell ampere
AnalogIn ALoad (PA_3); //Load ampere
float apvc, abatt, aload;
int main() {
pc.baud(115200);
pc.printf(“Photovoltaic cell x BQ25504 monitoring system\n”);
mkdir("/sd/mydir", 0777);
FILE *fp = fopen("/sd/mydir/sdtest.csv", "w");
if(fp == NULL) {
error("Could not open file for write\n");
}
fprintf(fp, "Photovoltaic cell x BQ25504 monitoring system\n");
wait(1);
fprintf(fp, "Date , VBatt , VPvc , ABatt , APvc , ALoad\n");
set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
while (true)
{
vbatt = VBatt.read();
vbatt = vbatt*4984;
pc.printf("vbatt(mVolt)= %.f\n",vbatt);
vpvc = VPvc.read();
vpvc = vpvc*3300;
pc.printf("vpvc(mVolt)= %.f\n",vpvc);
wait(1);
apvc = APvc.read();
apvc = apvc*3300;
apvc = apvc/1023;
apvc = apvc*1000;
pc.printf("apvc(mAmp)= %f\n", apvc);
abatt = ABatt.read();
abatt = abatt*3300;
abatt = abatt/1023;
abatt = abatt*1000;
pc.printf("abatt(mAmp)= %f\n", abatt);
aload = ALoad.read();
aload = aload*3300;
aload = aload/1023;
aload = aload*1000;
pc.printf("aload(mAmp)= %f\n", aload);
time_t seconds = time(NULL); //RTC
pc.printf("Time= %s\n", ctime(&seconds)); //RTC
fprintf(fp, "%s ,", ctime(&seconds));
fprintf(fp, "%.f ,",vbatt);
fprintf(fp, "%.f ,",vpvc);
fprintf(fp, "%f ,",abatt);
fprintf(fp, "%f ,",apvc);
fprintf(fp, "%f ,",aload);
wait(10);
if (eject == 0)
{
fprintf(fp, "Eject Succesfully \n");
fclose(fp);
pc.printf("Eject Succesfully \n");
}
else pc.printf("Eject OFF \n");
}
}
please let me know, where the problem is.
**sorry for my bad in english