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.

[参考译文] MSP430FR2476:msp430fr2476小端字节序吗?

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1132291/msp430fr2476-is-msp430fr2476-little-endian

器件型号:MSP430FR2476

您好!

是 msp430fr2476小端字节序吗?

我使用过早期的 MSP430g 系列、它是小端字节序。 我可以找到的所有文档都显示 MSP430是小端字节序。  

我在 MSP430FR2476中运行以下代码并附上结果。

#include <msp430.h> 
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

/**
 * main.c
 */
int main(void)
{
	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
	volatile uint8_t arr[5] = {0x88, 0x77, 0x66, 0x55};

	    volatile uint16_t byte_2,byte_1;

	    byte_2 = (uint16_t)( *((uint16_t *)&arr[1]) );

	    if(byte_2)
	       byte_1=0;

	    while (1)
	        ;
	return 0;
}

如果 MSP430FR2476是小端字节序。  在上图中、变量"byte_2"应为0x6677、但显示为0x7788。  

我缺少什么吗?

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

    您的错误是尝试从奇数地址访问整数。 除非编译器执行额外的指令从未对齐的地址构建整数、否则(这种情况很少见)您将始终得到该结果。 对于整数访问、地址的 lsb 始终为零。

    某些处理器具有自动执行未对齐访问的硬件、但 MSP430不是其中之一。

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

    不好的是、感谢回答@、当我在 PC 上运行相同的代码时、我感到困惑、它能够提供 0x6677。

    正如您所说的、MSP430不执行 未对齐的地址。 如果我尝试访问它正在工作的偶数地址。

    谢谢