我使用 TI C2000通过 SCI 从另一个可寻址8位的 MCU 接收数据
另一个 MCU 以两个字节的形式向 TI C2000发送数据、每个字节为8位、并且由于 TI C2000是16位 可寻址(字节为16位)、因此仅当复制接收变量时才能正确接收数据 (因此,我接收到两个变量,每个变量 的大小为 u_16)。 解决方案可以正常工作、但我不能说这是最好的解决方案
您是否有更好的解决方案来正确接收数据?
谢谢你
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.
我使用 TI C2000通过 SCI 从另一个可寻址8位的 MCU 接收数据
另一个 MCU 以两个字节的形式向 TI C2000发送数据、每个字节为8位、并且由于 TI C2000是16位 可寻址(字节为16位)、因此仅当复制接收变量时才能正确接收数据 (因此,我接收到两个变量,每个变量 的大小为 u_16)。 解决方案可以正常工作、但我不能说这是最好的解决方案
您是否有更好的解决方案来正确接收数据?
谢谢你
您好、Mohamed、
感谢您的提问!
作为开始说明:如果您愿意、实际上一次只能从另一个 MCU 接收一个字节、而不会出现任何问题。 默认情况下、它仍将存储在单个16位变量中、但我将把它更改为下面的"两个8位变量"。
如果您想节省空间(因为您不想对8位值使用16位变量)、只需使用按位或和移位的值、将两个8位值存储在16位变量的上半部分和下半部分。 与下面的伪代码类似:
uint16_t twoByteStorage; // every other byte, store in upper half: if (loopCount%2==0) { twoByteStorage = twoByteStorage | sciReadChar(*) << 8; } // store in upper half on even loop else { twoByteStorage = twoByteStorage | sciReadChar(*); } // store in lower half on odd loop
此致、
Vince
查看编译器内在函数 int &__byte (int * array、unsigned int byte_index);
如需了解更多相关信息、请参阅文档 https://www.ti.com/lit/ug/spru514y/spru514y.pdf?ts=1663236721522&ref_url=https%253A%252F%252Fwww.google.com%252F
https://software-dl.ti.com/ccs/esd/documents/c2000_byte-accesses-with-the-c28x-cpu.html 中有更多信息 、但我现在无法打开
uint16_t data = 0xABCD; uint16_t low_byte, high_byte; low_byte = __byte(&data, 0); //should load 0xCD to 'low_byte' high_byte = __byte(&data, 1); //should load 0xAB to 'high_byte