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.

CC2530 32位数操作问题

Other Parts Discussed in Thread: CC2530

我在基于CC2530+ZStack的环境下发现了这样一个比较奇怪的现象,操作32位数时高16位有问题。例如下面的代码按我以前的理解结果应该是:

11223344
2AAAAAAA
2AAA2AAA
00002AAA
55552AAA

但是实际输出结果是:

00003344
0000AAAA
00002AAA
00002AAA
00002AAA

感觉像是高16位操作高16位出现了问题。

    uint8 buf[32];
    uint32 data1 = 0x11223344;
    unsigned long data2 = 0xaaaaaaaa;

    sprintf(buf, "%08x\r\n", data1);
    HalUARTWrite(0, buf, strlen(buf));

    data2 &= ~(1 << 31);
    sprintf(buf, "%08x\r\n", data2);
    HalUARTWrite(0, buf, strlen(buf));

    data2 &= ~(1 << 15);
    sprintf(buf, "%08x\r\n", data2);
    HalUARTWrite(0, buf, strlen(buf));

    data2 &= 0xffff;
    sprintf(buf, "%08x\r\n", data2);
    HalUARTWrite(0, buf, strlen(buf));

    data2 |= 0x5555 << 16;
    sprintf(buf, "%08x\r\n", data2);
    HalUARTWrite(0, buf, strlen(buf));

这些代码加到ZStack自带的GenericApp里面就可以复现。是不是编译器有问题呢?我使用的IAR版本是8.10.1,编译的时候在移位超过16的地方会报“Warning[Pe063]: shift count is too large”的警告。但是随便搜了下ZStack里面有很多地方也会对32位数进行位操作,为此纠结了一整天。请问下谁知道这是为什么呢?

谢谢!