0
\$\begingroup\$

Devices: STM32F4

The SD is working and the data is saving on the SD, but the problem is that the integers are displayed as symbols in this SD. So I think that the problem is that the function I used needs char, and the data is int, so is there any way to convert int into char for 2 digits?

Code:

while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
        HAL_RTC_GetTime(&hrtc,&sTime,RTC_FORMAT_BIN);
        HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN);

char month = sDate.Month;

        /* Mount SD Card */
  if(f_mount(&fs, "", 0) != FR_OK)
Error_Handler();  
  /* Open file to write */
  if(f_open(&fil, "second.txt", FA_OPEN_ALWAYS | 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 */
    if(freq <=120000 && freq>= 80000){
          f_puts(&month, &fil);  
  f_puts("\n", &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();  

  }
  /* USER CODE END 3 */
}
\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

You are writing the variable data directly to the file. You need to convert the data into a printable text string of ascii symbols and write the string to the file. You can use sprintf to do it, almost like when printing to serial port with printf.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.