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.

Using File open ez dsp 5505

Hello. 

I am trying to read and write integers from a text file in Code compose using fopen and fprintf, however I am unable to open the file that I am reading from(give me a "Could not open data.txt". I am trying to write an application for students in my class, so I would like to figure this out quickly. 

FILE *filepointer;
FILE *file;
int character;
filepointer=fopen("coeff", "r+"); /* filepointer points to data.txt */

file=fopen("coeff", "r+");
//file = fopen("file.txt","r+"); /* apend file (add text to
//a file or create a file if it does not exist.*/

if (filepointer==NULL) { /* error opening file returns NULL */
printf("Could not open data.txt!\n"); /* error message */
//return 1; /* exit with failure */
}
while ((character=fgetc(filepointer)) != EOF) {
putchar(character); /* print the character */
//fprintf(file,"%c",character); /*writes*/
//printf ("%d ", i);
//fscanf (filepointer, "%d", &i);

}
/* Initialize BSL */
read_ints ("");
USBSTK5505_init( );

/* Initialize the Phase Locked Loop in EEPROM */
pll_frequency_setup(100);

/* Initialise hardware interface and I2C for code */
aic3204_hardware_init();

/* Initialise the AIC3204 codec */
aic3204_init();

printf("\n\nRunning FIR Filters Project\n");
printf( "<-> Audio Loopback from Stereo Line IN --> to HP/Lineout\n\n" );

/* Set sampling frequency in Hz and ADC gain in dB */
set_sampling_frequency_and_gain(SAMPLES_PER_SECOND, GAIN_IN_dB);

puts("1 Flash = Straight through, no processing");
puts("2 Flashes = Hamming filter 500 Hz");
puts("3 Flashes = Hamming filter 1000 Hz");
puts("4 Flashes = Hamming filter 2000 Hz");
puts("5 Flashes = Hamming filter 3000 Hz");

asm(" bclr XF");

for ( i = 0 ; i < SAMPLES_PER_SECOND * 600L ;i++ )
{

aic3204_codec_read(&left_input, &right_input); // Configured for one interrupt per two channels.

mono_input = stereo_to_mono(left_input, right_input);

step = LEDFlasher(5); // 5 Different filter settings.

switch (3)
{
case 1:
left_output =FIR_filter_asm(&NoDelay[0], mono_input); // Straight through, no processing.
//left_output = mono_input; // Straight through, no processing.
//right_output = mono_input;
right_output = FIR_filter_asm_2(&Delay[0], mono_input);
break;

case 2:
left_output = FIR_filter_asm(&Hamming_Low_Pass_Filter_500Hz[0], mono_input);

right_output = FIR_filter_asm_2(&Hamming_High_Pass_Filter_500Hz[0], mono_input);
break;

case 3:
left_output = FIR_filter_asm(&Hamming_Low_Pass_Filter_1000Hz[0], mono_input);
right_output = FIR_filter_asm_2(&Hamming_High_Pass_Filter_1000Hz[0], mono_input);
puts(""+left_output);
break;

case 4:
left_output = FIR_filter_asm(&Hamming_Low_Pass_Filter_2000Hz[0], mono_input);
right_output = FIR_filter_asm_2(&Hamming_High_Pass_Filter_2000Hz[0], mono_input);
break;

case 5:
left_output = FIR_filter_asm(&Hamming_Low_Pass_Filter_3000Hz[0], mono_input);
right_output = FIR_filter_asm_2(&Hamming_High_Pass_Filter_3000Hz[0], mono_input);
break;
}

aic3204_codec_write(left_output, right_output);
}

/* Disable I2S and put codec into reset */
aic3204_disable();

printf( "\n***Program has Terminated***\n" );
SW_BREAKPOINT;
}

  • I should also mention that I have tried reading and writing these files using gcc and it run perfectly, so I think it is something that I am not doing correctly with the settings of Code composer.

    ~Avik

  • Hi Avik,

    Try it this way...

    void file_read(char *fileName)
       FILE *pInputFile = NULL;
       unsigned short FileData[2];
       unsigned short OutData;
       unsigned long addr = 0x0000;   /* start address is 0 */
       size_t rcv_count;

       pInputFile = fopen(fileName, "rb");
       if (pInputFile == NULL)
       {
          printf("Unable to find file!\n");
          exit(2);
       }

       while (!feof(pInputFile))
       {
          rcv_count = fread(FileData, 1, 2, pInputFile);
          if (rcv_count == 0)
          {
             break; /* no more data to read */
          }
          if ((rcv_count & 1) != 0)
          {
             printf("Input File has an odd number of bytes (invalid)\n");
             exit(1);
          }
          OutData = (FileData[0] << 8) | FileData[1];
          addr++;
       }
       fclose(pInputFile);
    }

    Hope this helps,
    Mark

  • Hello Mark,

    I tried your code and it still did not work. Furthermore, the second time I tried it I got a weird error that wont let me run my board in debug mode anymore. Everytime I try to run the debugger I get:

    Error connecting to the target:
    Error 0x80000242/-1143
    Fatal Error during: Memory, Initialization, OCS,
    The memory at 0x0000005F continually indicated it was 'not ready'
    All memory operations currently in progress were aborted in order
    to regain control of the processor.
    This is considered a catastrophic event, but the debugger should
    still be able to access memory and CPU registers.
    System state has been altered. It is strongly advised
    that the processor should be reset before resuming execution,

    No matter what I do(even reverting to my original code that worked perfectly)I am unable to get rid of this problem. I am using a TMS 5505 ezdsp, which i dont think has a reset button, so I am unable to do anything with that. Any advice?

  • Hi Avik,

    Is the XDS100 appearing correctly in the device manager?

    See http://e2e.ti.com/support/dsp/tms320c5000_power-efficient_dsps/f/109/t/69484.aspx

    I don't know if that helps or not. What else did your program perform?

    Also did the EEPROM programmer work correctly? I ask because that program performs file reads to copy the .bin boot image to EEPROM...

    -Mark

  • Mark,

    Thanks for the help, Now it is managing to work, after I power cycled the board and my computer and let everything sit, somehow I stopped getting that error, I'm not exactly sure how that took care of the error, but it worked.. However, I am still having trouble reading and writing to files.

  • Hi Avik,

    Strange behavior but I'm glad you are able to move past this emulator issue... The CVDD/CVDDRTC 1.3V rail does have a slow RC discharge curve when power is removed from the board - I just scoped 2 seconds between 1.3V and 0.2V...

    The Chip Support Library (v03.00.00.02) includes source code for the programmer project. This project copies a boot image files from the Windows file system into one of the non-volatile memories on the EVM - file I/O is performed through the CCS console.

    This project does not support white spaces in the file path to the boot image file...

    Try the file I/O in the programmer project to see if it works for you, then the project can be a useful debugging reference or good starting point for your project.

    Download CSL v03.00.00.02 from http://www.ti.com/tool/sprc133

    Hope this helps,
    Mark