AnsweredAssumed Answered

FATFS name generator for txt file

Question asked by Kilohercas on Nov 13, 2012
Latest reply on Nov 13, 2012 by Kilohercas
Hello, i am working on project where i need to save array stored in stm32 to sdcard
problem is i was able to make it work using clive1 project, but somehow i was unable to crate new file.
Idea that i press button on PA0, and in interrupt i write  all data from  array to sdcard.
int spektras  = 1 ;
void EXTI0_IRQHandler(void)
{
  if(EXTI_GetITStatus(EXTI_Line0) != RESET)
  {
    FATFS fs[1];         //  Work area (file system object) for logical drives
    FIL ftxt;                 //  file objects
    char buffer[50];   //  file copy buffer
    char name[14];
    FRESULT res;         ///FatFs function common result code
    UINT bw;               // File write count
    f_mount(0, &fs[0]);//
    ///Create destination file on the drive 0
    sprintf(name,"0:%dspektras.txt",spektras);
    res = f_open(&ftxt, name, FA_CREATE_ALWAYS | FA_WRITE);
    long cnt=0;   
    while (cnt<1000)
    {
      sprintf(buffer,"%f\n",sinf(cnt*0.00628318531));
      res = f_write(&ftxt, buffer, strlen(buffer), &bw);  
      cnt++;
    }
    f_close(&ftxt);
    f_mount(0, NULL);//
    spektras++;
    EXTI_ClearITPendingBit(EXTI_Line0);
    LCD_Clear(YELLOW);
  }
     
}
i get empty card, but if i don't write %d i get data, but it override data to old txt file.
Any ideas how to crate new txt with new name?

Outcomes