This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I want to read data present in a '.txt' file into a float array in the MSP430. I have installed the FatFs library in my project and have also looked at some example codes written for performing the basic tasks of opening, reading and writing the files using this library. I have a doubt regarding the implementation of these examples on my MSP430. Do I need to store the FatFs on an SD Card or do I load it in my project and load an SD Card that contains the files I need to read from? Also, another part that I am confused about is the use of fmount() and the concept of drives used in the FatFs. How can the different drives be created or considered on MSP430 if at all they are needed. I have created a preliminary code sample of what I want to achieve on the MSP430 as follows:
#include <stdio.h> #include <msp430.h> #include <stdlib.h> #include <string.h> #include "DSPLib.h" #include "ff.h" FATFS FatFs; int main() { WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer FIL fil; char line[100]; FRESULT fr; int i; float bias3[2], num; fr = f_open(&fil, "bias3.txt", FA_READ); if (fr) return (int)fr; while (f_gets(line, sizeof line, &fil)) { printf(line); } f_close(&fil); return 0; }
I tried to adapt the code that I found in the example such that I can read a simple txt file containing two float values into my array. This code tries to read the data line by line. The data file is structured as follows:
-0.08071705 0.08071705
While currently my file is in the project folder, I know that I need to move it onto either an SD card or some location where the file system can find it. Do I need to use the SDCardLib available in the MSP430 as well or is there a different way of accomplishing the same? I am trying to look for some examples but so far have only come up with very basic answers from which I couldn't extract much information. Any kind of leads or ideas would be very helpful. Please let me know if any more information is required as well. Thank you.
Does the above code work?
If so, you should be able to use sscanf() to get your values into the mcu.
Hey Keith, this code as it is does not work currently. However, I am yet to upload an SD Card that contains this file. My file is presently in the project folder. Would that change something? Or do I need to try an alternate implementation in terms of the code I am using. I am a bit unsure about how the SD Card is supposed to fit in while using the FatFs system. Pardon my ignorance about some fundamentals here as I have never tried some implementation like this before. Thanks!
I am afraid that I have only used FatSD on the MSP432, I can't help much on the MSP430.
Alright, I will have a look at other resources that I have come across and check them out. I will keep the issue open so that anyone else who might have worked on it could possibly respond to it. Thanks though for the idea you suggested.
I found the Out-of-Box Demo quite useful for understanding some of the concepts used in creating or rather installing a FATFs filesystem. Also, I have found an easier way to read in the data using the fopen, fscanf commands via the stdio library - the other question can be found on this link - https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1063552/msp430fr5994-input-data-from-csv-file-into-an-array-at-compile-and-run-time/3937259?tisearch=e2e-sitesearch&keymatch=%20user%3A504252#3937259 - I am now closing the issue as I do not have any specifc queries related to the FatFS. In case anyone would like to know any details about the question, feel free to connect with me about the same. Thanks!
**Attention** This is a public forum