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/MSP430F6638: Can't write in a text file with CCS studio

Part Number: MSP430F6638
Other Parts Discussed in Thread: MSP-FET

Tool/software: Code Composer Studio

Hello,

I am using the msp430f6638 and I am collecting some data from the ADC. I would like to write these data in a text file. So I have written the code to create a file and to open it. When I execute the program it does create the text file but once I stop the program the text file remains empty, the values that I want to write in it are not written in this text file. Here is the code :

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

int main(void)

{

FILE* fichier = NULL;

fichier = fopen("ADC_TEST.txt", "w");

while (1)
{
if (write_mem==1)
{
write_mem=0;
ADC_value = converted_value;
tab[i]=ADC_value;
i++;
}

if (fichier != NULL)
{
fprintf(fichier,"%d\n",ADC_value);

}

else
{
printf("error");
}

}

fclose(fichier);

}

#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)
{

converted_value = ADC12MEM0 & 0x0FFF; // in order to keep only the low 12 bits
ADC12IFG &=~ADC12IFG0;
write_mem = 1;
}

As you can see it's a really simple code and despite that I can't fill in the text file. With this code I am able to create the file but not to write it and I don't know why. The code to create the file is the same I have used before for another project with another MCU and it worked very well. So I am wondering if it's because of the mcu or CCSstudio or maybe a code error, I really don't know how to resolve that. Any help would be appreciated.

Thank you,

Best regards, 

Mike

  • Hi, 

    1. How can you pass the build without inlcude "msp430.h"

    2. If the code you want to run on MSP430. I don't think it has the ability to create a .txt file on its RAM.

    3. Can you show me the text file is created at which place? In the ccs workspace?

    Eason

  • Hi Eason,

    1) I have included msp430.h in my code, it doesn't appear here beacuse i didn't post obvious line code such as this one. I have mentionned these two #include <stdio.h> #include <stdlib.h> in order to show that I didn't forget them.

    2) I don't want to create a file text in the mcu RAM. I want to create a file text on the PC documents. I mean i am still debugging and using the msp-fet. I just need when I run my code with ccs studio to be able with some c code to create and write a text file that will be located in the project folder of cssstudio on the PC. 

    3) The text file is created in the ccsstudio project folder that I am working on and precisely in the folder named Debug. As I said I am with the code I posted able to create the text file and I can find it in the debug folder of the ccsstudio folder project (in PC documents) but it remains empty and I don't know why. Do you see any mistake in the code or is there something that I need to enable or do with ccsstudio to resolve that ?

    Thank you,

    Regards,

    Mike

  • Hi Mike,

    Thank you for your detailed explain.

    I think the problem mostly related to CCS not MSP430. I will move this thread to CCS.

    Eason 

  • Could someone help please ?

    Thank you.

    Mike

  • Hi Mike,

    I am sorry that because of the internet problem. The re-assign action failed.

    Eason

  • Hi Mike,

    Have you seen the below article?

    https://processors.wiki.ti.com/index.php/Printf_support_for_MSP430_CCSTUDIO_compiler

    At the very least, you'll likely need to bump up the heap size. The suggested 320 byte value worked for me.

    Thanks

    ki

  • Hi Ki.

    I have changed the heap size to 320 byte and still nothing. I have tried a really simple code and still nothing. Here is the code.

    int flg=1;

    FILE* fichier = NULL;
    fichier = fopen("ADC_TEST.txt", "w");

    while (1)
    {

    if (fichier != NULL)
    {
    fprintf(fichier,"%d\n",flg);

    }

    else
    {
    printf("error");

    }

    }

    fclose(fichier);

    I have put a breakpoint after the fprintf line and the program is able to reach this line. I mean the file is well created, the program can reach the fprintf line but I can't write the file, it remains empty. So I guess the problem comes from the debugger that is not able to write the file, right ? I really don't know how to resolve this, I mean it's a really simple code and nothing is written in the file. Is there anything I did wrong ?

    Thank you,

    Regards,

    Mike

  • Mike Jaber said:
    I mean the file is well created, the program can reach the fprintf line but I can't write the file, it remains empty.

    This usually indicates a heap issue. The code example you provided looks fine. Can you zip up your whole sample project and attach it to this thread?

    Thanks

    ki

**Attention** This is a public forum