AnsweredAssumed Answered

FAT write problem uin sd card

Question asked by d.rajesh.001 on Aug 16, 2016
Latest reply on Sep 8, 2016 by d.rajesh.001
hi,
     i am trying to do a data logger using FAT with sd card.

in the below code trying to write in sd card with 100ms interval, the code has write into sdcard at only one time.
latter it has gone to error




01./*##-1- Link the micro SD disk I/O driver ##################################*/
02.  if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)
03.  {
04.    /*##-2- Register the file system object to the FatFs module ##############*/
05.    if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK)
06.    {
07.      /* FatFs Initialization Error */
08.      Error_Handler();
09.    }
10.    else
11.    {
12.      /*##-3- Create a FAT file system (format) on the logical drive #########*/
13.      /* WARNING: Formatting the uSD card will delete all content on the device */
14.//      if(f_mkfs((TCHAR const*)SDPath, 0, 0) != FR_OK)
15.      {
16.        /* FatFs Format Error */
17.        Error_Handler();
18.      }
19.//      else
20.      {
21. 
22.  while(1)
23.    {
24.        /*##-4- Create and Open a new text file object with write access #####*/
25.        if(f_open(&MyFile, "STM32.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
26.        {
27.          /* 'STM32.TXT' file Open for write Error */
28.          Error_Handler();
29.        }
30.        else
31.        {
32. 
33. 
34.                  /*##-5- Write data to the text file ################################*/
35.                  res = f_write(&MyFile, wtext, bytesread, (void *)&byteswritten);
36.//                while(byteswritten != bytesread)
37.                  {
38.                      BSP_LED_Toggle(LED1);
39.//                    HAL_Delay(1000);
40. 
41.                  }
42.                  f_close(&MyFile);
43.                  HAL_Delay(100);
44. 
45. 
46.            }
47. 
48.    }
49.            {
50.}


what is the way to make a data logger using STM32F746G.disco baord

regards
Rajesh

Outcomes