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.

[参考译文] MSP430FR2355:正在尝试初始化结构内的数组?

Guru**** 2537350 points


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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1017842/msp430fr2355-trying-to-initialize-an-array-that-is-within-a-struct

器件型号:MSP430FR2355

h 文件中包含以下内容:

typedef struct
{
    uint8_t Channels[10];      /*values @CHANNELS */
    uint32_t Rate;              /*sample rate */
    uint8_t CycleSeqence;       /*values @CYCLE */
    uint8_t TriggerSrc;         /*values @TRIGGER */
    uint8_t TriggerChannel;     /*values @CHANNELS */
    uint16_t TriggerLevelLow;
    uint16_t TriggerLevelHigh;
}ADC_Config_t;

在 main 中、我尝试执行以下操作、但似乎无法使其正常工作

ADCTest.ADC_Config.Channels[] = {ADC_CH3, ADC_CH1, ADC_CH2};

在单个行中是否有方法可以初始化阵列而不使用三条单独的行、每个元素一条(顺便说一下、这条行是有效的)?

我正在使用 C99编译器

谢谢

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

    您好!

    我认为.channel[10]是一个10字的数组。 您只能在 main 中向其写入3个字。 您可以尝试一次写入10个字、并检查它是否可以正常工作。

    此致、

    现金 Hao

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

    这仅适用于初始化。 在运行时、您需要使用一系列赋值。