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.

[参考译文] MSP430FR5994:在 CCS 中读取外部.dat 文件

Guru**** 2390170 points
Other Parts Discussed in Thread: MSP430FR5994
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1055497/msp430fr5994-reading-an-external-dat-file-in-ccs

器件型号:MSP430FR5994

您好!

我有一个包含一些'.dat '格式的浮点数据的文件。 我知道要读取文件并将其存储在数组中的 C 代码、并且我正在使用相同的代码-但是、当我将程序加载到我的 MSP430FR5994 Launchpad 上时、程序会继续运行、但无法在控制台窗口中打印任何内容。 我以前曾读过一些有关 CCS 中'.dat '文件的格式如何不同的问题-特别是头 文件-但我无法找到最新 CCS 的确切文档、其中描述了如何重新构建文件以便可以读取 我也不知道这是否是我在文件中唯一需要做的更改。

我要附加'.ddat'文件和我用于读取相同内容的代码以供参考。 如果有人能将我重新引导到必要的链接、那将非常有帮助。 我将继续在论坛上搜索它、如果我发现它、将相应地更新此处的帖子。 谢谢!!

e2e.ti.com/.../sample.dat  

float spectrum[1024];

    FILE *sampleFile;               // Pointer to the sample data file

    int i = 0;                     // Index counter - used to keep track of which data point is being read in

    unsigned int coeff;           // Determine which MFCC coefficient to compute

    float mfcc_result;           // Holds the value of the computed coefficient

   //  printf("Sample is: %d", 4); // Test statement to check where the code stops working

    memset(spectrum, 0, sizeof(spectrum));        // Initialize the spectrum

    sampleFile = fopen("sample.dat","r");         // Open the sample spectrum data

    // Read in the contents of the sample file
    while(!feof(sampleFile))
    {
        fscanf(sampleFile, "%f", &spectrum[coeff++]); // %f tells fscanf to read a float
    }
    fclose(sampleFile);

    for(i=0;i<13;i++)
    {    printf("%d, %f", i, spectrum[i]);

    }

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Siddhant、

    因此、我可以更好地了解您的设置:

    您是否使用 MSP430FR5994 Launchpad?

    您是否正在使用 Code Composer Studio (CCS)?

    您读取的.dat 文件是否位于您的 PC 上?

    当您运行 printf ("Sample is:%d"、4)时;在哪里可以看到输出?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Dennis、

    我将 MSP430FR5994 Launchpad 与 CCS 搭配使用。 dat 文件位于我的 PC 中、我已将其添加到我的 CCS 项目中。  

    对于 printf 语句、我会在 CCS 的控制台中看到输出。 如果您需要任何其他信息、请告诉我。

    谢谢!

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我不确定代码中是否总是需要进行看门狗初始化、但我添加了相同的内容、下面是我针对上述问题的完整 main.c 文件:

    #include <stdio.h>
    #include <string.h> // For memset
    #include <msp430.h>
    #include "lib_mfcc.h"
    
    int main(void)
    {
        // Read in sample data from sample.dat
        // sample.dat contains an 8192-point spectrum from a sine wave at 440Hz (A) in float precision
        // Spectrum was computed using FFTW (http://www.fftw.org/)
        // Data was not windowed (rectangular)
    
        // Holds the spectrum data to be analyzed
        WDTCTL = WDTPW | WDTHOLD;
    
        float spectrum[1024];
    
        FILE *sampleFile;               // Pointer to the sample data file
    
        int i = 0;                     // Index counter - used to keep track of which data point is being read in
    
        unsigned int coeff;           // Determine which MFCC coefficient to compute
    
        float mfcc_result;           // Holds the value of the computed coefficient
    
        printf("Sample is: %d", 4);
    
        memset(spectrum, 0, sizeof(spectrum));        // Initialize the spectrum
    
        sampleFile = fopen("sample.dat","rb");         // Open the sample spectrum data
    
        // Read in the contents of the sample file
        while(!feof(sampleFile))
        {
            fscanf(sampleFile, "%f", &spectrum[i]);      // %f tells fscanf to read a float
            i++;
        }
        fclose(sampleFile);
    
        for(i=0;i<13;i++)
        {    printf("%d, %f", i, spectrum[i]);
    
        }
        // Compute the first 13 coefficients
    //    for(coeff = 13; coeff > 0; coeff--)
    //    {
    //        mfcc_result = GetCoefficient(spectrum, 44100, 48, 128, coeff);
    //        printf("%i %f\n", coeff, mfcc_result);
    //    }
    //    getchar();
        return 0;
    }
    

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我不确定具体的问题是什么,但您是否在从此文件中读取后验证了 spectrum []包含浮点值?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Dennis、

    频谱数组仅使用 memset 进行初始化-在调试时、我尝试观察代码发生的情况、看起来在'fopen'之后执行操作不起作用。 最初、我认为这可能是由于数据文件的大小 -但是、我将数据文件的大小从最初的20KB 减少到了11KB。 我已经在 FRAM 的帮助下分配了所需的存储器。 代码的执行绝不会超过 while 条件。 我不确定为什么会发生这种情况 -我将数据文件附加到这里供您参考。 如果您需要任何其他信息、请告诉我。 谢谢!

    e2e.ti.com/.../5228.sample.dat

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Siddhant、

    好的、让我深入探究一下我的 MSP430F5994 Launchpad 并尝试一下。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Dennis、

    如果您需要参考、我将以文本格式附加链接器文件-以检查上述代码的内存分配变化。

    e2e.ti.com/.../linker.txt

    谢谢、

    Siddhant

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Siddhant、

    根据我发现的情况和被告知的情况、MSP430无法直接从 PC 读取文件。

    下面是另一个发布的问题、询问相同的问题-> 链接

    一种方法是使用 Launchpad 的反向通道 UART。  您将需要在 PC 上编写程序以读取.dat 文件并通过 UART 发送此数据、或者某些终端应用程序允许您读取文件并发送数据。

    这是一 个->链接、但本主题还有许多其他链接。

    我恐怕这是我在这个问题上能为您做的最好的事情。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Dennis、

    感谢您的回复。 现在、我了解一下代码不起作用的原因、我将查看您提到的链接、看看我是否可以尝试这些链接并使其正常工作。 我只需要使用此功能进行测试、但我将查看这些帖子、如果我确实找到了适合我的内容-我将会指出、我的解决方案需要更新此问题、但现在、 我将使用您的最后答案更新此问题。 再次感谢您的回答。  

    此致、

    Siddhant