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.

CCS/MSP430F5529: Unable to read a .csv file

Part Number: MSP430F5529

Tool/software: Code Composer Studio

Hello Team,

I want to read a .csv file for my algorithm but it doesnot work in CCS7. The same code I tried in IAR and it is working. Please can you tell me how to make it work in CCS.

#include <msp430.h> 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main()
{
    FILE* stream = fopen("data.csv", "r");
    if(stream == NULL)
        exit(1);
    char line[10];
    if((fgets(line, 10, stream))!=NULL)
    {
        char* tmp = strtok(line,",");
        free(tmp);
    }
}

Regards,
Soumit

  • Soumit,

    The first detail that caught my eye on this is that you are missing the line that disables the watchdog timer - you should have something similar to:

    WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

    Another detail that should be considered is the heap and stack sizes for console I/O operations. Details shown at sections 2.3 and 2.4 of the following page:

    processors.wiki.ti.com/.../Tips_for_using_printf

    Hope this helps,
    Rafael
  • Hello Rafael,

    Sorry not stopping the watchdog timer was a silly mistake from my side. I have already changed the heap and stack memory to 0x800 but still i am not able to read the file. It is compiling without error but stream shows NULL and exiting.

    include <msp430.h> 
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    int main()
    {
    
        WDTCTL = WDTPW | WDTHOLD;       // stop watchdog timer
    
        FILE* stream = fopen("data.csv", "r");
        if(stream == NULL)
            exit(1);
        char line[10];
        if((fgets(line, 10, stream))!=NULL)
        {
            char* tmp = strtok(line,",");
            free(tmp);
        }
        fflush(stream);
        fclose(stream);
    }

  • Soumit,

    Please apologize for the delay. Were you able to workaround this issue?

    I found out that I am reading the .csv file just fine using the same features as yours. The only issue I am seeing is the unexpected call to free(), which is tripping the device to la la land.

    Check the short clip below with the procedure I am running.

    Perhaps you are doing something different?

    Regards,

    Rafael

  • Hello Rafael,

    Have you changed anything else other than the heap and stack size (under Linker Basic options)?  Unfortunately I am doing the same but not able to read. It exits after the 'if' statement.

    Regards,

    Soumit

  • When I had this problem, it was because the fopen was looking in a different directory than I expected. Maybe you could start with a call to create an empty sample file just so you could verify what it considers the working directory.

    Lloyd
  • Soumit,

    Just for verification, please check the project I am using attached. This way you will be able to compare all its settings.

    Also, Lloyd's idea is good. The default path to the file is located at the same place as the .out executable - in my case, the "Debug" directory under the project. You can always try to set a hardcoded path to a temp directory (don't forget to use double backslashes for path separator)  in your drive where you have R/W access.

    Hope this helps,

    Rafael

    F5529_CIO_stream.rar

  • Thank you Rafael and Lloyd for helping me out!!
    Perhaps it was looking in Debug directory and the data.csv file was in my project folder.

    Regards,
    Soumit