AnsweredAssumed Answered

Newbie Query: Storing Count values in Text File (FATFS-SDIO)

Question asked by Lyen.Rum on Jan 2, 2016
Latest reply on Jan 3, 2016 by Lyen.Rum
I want to store consecutive Timer counts (32bit) to a text file. To avoid SDIO write for every count, I've tried to store in a string first and SDIO write after 40 counts (for example). Can we store values column-wise using '\n' in 'sprintf' command?
I have not succeeded. Also, what would be the appropriate string size?
Is there any other simpler methods to store buffer/count values in a Text file?
Thank you in advance for your kind reply.

char string[size];    // What would be appropriate string size?
void StoreSD(void)
{
 memset(&fs32, 0, sizeof(FATFS));
 res = f_mount(0, &fs32);
 memset(&fil, 0, sizeof(FIL));
 if (f_open(&fil, "Data.TXT", FA_OPEN_ALWAYS | FA_WRITE) == FR_OK)
  { 
    f_lseek(&fil, fil.fsize);
    f_write(&fil, string, strlen(string), &BytesWritten);
    f_close(&fil);
  }
}
int main()
{
 while (1)
   { 
     if(WriteIndex == 40)   // Storing 40 Timer counts (32-bit)
   {
   TIM5->CNT = 0;         // Reset TIM5 Count value
   StoreSD();
   WriteIndex = 0;
   .......
   .......
  
   }
   else
   {
   sprintf(&string[WriteIndex],"%ld%s",TIM5->CNT,"\t");   // Store 32-bit Count value to a string with a 'tab'. '\n' doesn't work.
  
   TIM5->CNT = 0;                 // Reset TIM5 Count value
   WriteIndex=WriteIndex+6;       // Next 32-bit Count store index. only 6 works. why '6' ?
   }
  
   }
  
  }

Outcomes