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.

[参考译文] MSP430FR2433:MSP430不能乘以32

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1344765/msp430fr2433-msp430-i-cant-multiply-by-32

器件型号:MSP430FR2433

大家好!

我正在用 msp430fr2433编写代码、对 fr2433不太熟悉。

我在使用移位和乘法等操作数时遇到了困难。

这里有一个示例代码块:

void write(uint8_t GPIO,uint64_t pin,uint16_t addr,uint8_t * data,uint16_t datasize)
{

uint32_t myData = (addr * 32);
// multiply by 32 does not work.


uint32_t myData = (addr * 2);
myData = (myData * 16);
// i workaround the problem like this


}

我将0x1100作为 addr 参数传递。 我想其他参数等不重要。

当我乘以32得到0x2000时、结果应该为0x22000。 我不知道为什么。

但是、当我尝试使用2和16来实现熵时、可以得到。 结果为0x22000。

我试图移动操作数、但这不起作用。 因为我研究过 msp430fr2433、它没有多移位操作数。 它似乎无法在一个周期内对变量移动超过1位。

我不明白为什么不能把数字乘以32。

提前感谢  

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

    > uint32_t MyData =(addr * 32);

    为此、"addr"被提升至"unsigned"、在 MSP430上为16位、然后乘以32 (在顶部截断结果)、然后提升为 uint32_t。 (这在32位 CPU 上会有所不同、其中"unsigned"是32位。) 请尝试改用:

    > uint32_t MyData =(addr * 32UL);

    或者、如果您愿意:

    > uint32_t MyData =((uint32_t) addr * 32);