The code is to log data in multiple files on SD card. The problem is that the SD card only opens and saves 1 file. When the if condition occurs in the 2nd time, the old file is deleted and the SD card is empty.
The condition here is that if a
is between 110000 && 95000, time should be logged into the SD Card.
code:
char hours[5];
char seconds[2];
char min[2];
char year[4];
char month[2];
char day[2];
sprintf(hours, "%d" , sTime.Hours);
sprintf(day, "%d", sDate.WeekDay);
sprintf(seconds, "%d", sTime.Seconds);
sprintf(min, "%d", sTime.Minutes);
sprintf(year, "%d", sDate.Year);
sprintf(month, "%d", sDate.Month);
/* Mount SD Card */
if(f_mount(&fs, "", 0) != FR_OK)
Error_Handler();
/* Open file to write */
if(a <=110000 && a>=95000) {
if(f_open(&fil,"second.txt", FA_CREATE_NEW | FA_READ | FA_WRITE) != FR_OK)
Error_Handler();
}
/* Check free space */
if(f_getfree("", &fre_clust, &pfs) != FR_OK)
Error_Handler();
total = (uint32_t)((pfs->n_fatent - 2) * pfs->csize * 0.5);
free1 = (uint32_t)(fre_clust * pfs->csize * 0.5);
/* Free space is less than 1kb */
if(free1 < 1)
Error_Handler();
/* Writing text */
f_puts(hours, &fil);
f_puts(min, &fil);
f_puts(seconds, &fil);
f_puts("\n", &fil);
f_puts(year, &fil);
f_puts(month, &fil);
f_puts(day, &fil);
/* Close file */
if(f_close(&fil) != FR_OK)
Error_Handler();
/* Open file to read */
if(f_open(&fil, "second.txt", FA_READ) != FR_OK)
Error_Handler();
while(f_gets(buffer, sizeof(buffer), &fil))
{
//printf("%s", buffer);
}
/* Close file */
if(f_close(&fil) != FR_OK)
Error_Handler();
/* Unmount SDCARD */
if(f_mount(NULL, "", 1) != FR_OK)
Error_Handler();
second.txt
, so that's the only file you'll see. You're also opening it with theFA_CREATE_NEW
flag, so every time you run this code, it'll be re-created as an empty file - because that's what you asked for. \$\endgroup\$ – brhans May 25 '20 at 1:38"second.txt"
. If you want multiple files then you would surely need to open different files ... ? \$\endgroup\$ – brhans May 25 '20 at 14:14