我的C代码有问题,标题有错误。首先,Uint16定义为:

typedef unsigned int    Uint16;

我在得到错误的函数中使用了两个变量,它们被定义为:
static Uint16 gCommandSent = 0;
Uint16 gnRF_TX;

我这样调用函数:
Transmit_nRF24L01(gnRF_TX, &gCommandSent);

函数定义如下:
void Transmit_nRF24L01(Uint16 nRF_TX,Uint16 *CommandSent)
{
    switch(CommandSent)
    {
    case 0:
        SpiaRegs.SPITXBUF = W_REGISTER | nRF24L01_CONFIG;
        *CommandSent = 1;
    case 1:
        SpiaRegs.SPITXBUF = CONFIG_TX;
        *CommandSent = 2;
    case 2:
        SpiaRegs.SPITXBUF = W_TX_PAYLOAD;
        *CommandSent = 3;
    case 3:
        SpiaRegs.SPITXBUF = nRF_TX;
        *CommandSent = 4;
    case 4:
        disable_TX();
        GpioDataRegs.GPBSET.bit.GPIO59 = 1;
        *CommandSent = 0;
    }
}

最后,共享头文件中的声明如下所示:
void Transmit_nRF24L01(Uint16 nRF_TX,Uint16 *CommandSent);

我在“switch(CommandSent)”一行看到错误。我需要能够更改CommandSent的值,所以很遗憾我无法删除指针。。。我该怎么解决这个问题?
提前谢谢!

最佳答案

您缺少break语句,需要对switch使用取消引用:

void Transmit_nRF24L01(Uint16 nRF_TX,Uint16 *CommandSent)
{
    switch(*CommandSent)
    {
    case 0:
        SpiaRegs.SPITXBUF = W_REGISTER | nRF24L01_CONFIG; break;
    case 1:
        SpiaRegs.SPITXBUF = CONFIG_TX; break;
    case 2:
        SpiaRegs.SPITXBUF = W_TX_PAYLOAD; break;
    case 3:
        SpiaRegs.SPITXBUF = nRF_TX; break;
    case 4:
        disable_TX();
        GpioDataRegs.GPBSET.bit.GPIO59 = 1; break;
    }
    *CommandSent = (*CommandSent + 1) % 5;
}

关于c - #31表达式必须具有整数类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23339858/

10-09 07:12