我的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);
我在线路上得到错误"切换(CommandSent)"。我需要能够更改CommandSent的值,所以很遗憾我无法删除指针......我该如何解决这个问题?
提前致谢!
答案 0 :(得分:3)
您缺少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;
}