Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

How use f_write in Fatfs library to save data

Home Forums MPLAB XC8 Tutorial Discussions How use f_write in Fatfs library to save data

This topic contains 8 replies, has 2 voices, and was last updated by  Bitahwa Bindu 6 months ago.

  • Author
    Posts
  • #3076

    MiguelParra
    Participant

    Hello my question is short, I am using the FatFs library: ¿how can I write data in the .txt file?, not words. For example, analog-to-digital conversion data is obtained.

    I just need to know how I use the f_write function to put a floating number in the .txt file. i tried changing the float to char, but it does not work.

     

    Thank you for yours respons

  • #3106

    Bitahwa Bindu
    Keymaster

    It explained in the tutorial, replace “buff” which is the pointer to the data to be written with your variable containing your data (your floating point data).

    Change the “Hello world …” with your variable.

    • #3111

      MiguelParra
      Participant

      thank you for your answer.

      i did it, but the problem is the number of the bytes to write in the SD. it’s necessary to put in this place the exact quantity.

       

  • #3112

    Bitahwa Bindu
    Keymaster

    You can find out how many bytes are in the Float. The other best option so that your data can be readable is to convert it to string, use the function sprintf()  to convert Float to string then use The  f_printf  function writes formatted string to the file.

    • #3118

      MiguelParra
      Participant

      Thank you very much for responding again.

      I have already managed to write data of 5 bytes, changing them to a variable type “char” and sending the address of this variable.

      Now I have had problems simulating. usually the file is created and the data is stored correctly, but in some occasions the image used in the simulation is damaged and the .txt file can not be opened.

      Software: MPLAB x IDE v4.05
      simulation software: MPLAB x IDE v4.05
      program to create and view the image of SD memory: Winimage

      Attachments:
      You must be logged in to view attached files.
    • #3122

      MiguelParra
      Participant

      Simulation software: proteus 8 *

  • #3123

    Bitahwa Bindu
    Keymaster

    Hi. Good to hear that at least you are managing to write data correctly. Unfortunately our knowledge with winimage is very limited. You can’t advise you why the file gets corrupt. Maybe you can get a better response from winimage Forum or support.

    How are you simulating the SD card with MPLAB X IDE?

    • #3124

      MiguelParra
      Participant

      the simulation is done in proteus 8.

      thanks for everything. see you soon.

  • #3125

    Bitahwa Bindu
    Keymaster

    You are welcome!

You must be logged in to reply to this topic.