我正在尝试从特定寄存器中读取某些值。手册规定我必须先访问 16 位 LSB,然后再访问 16 位 MSB。我是否只一次读入所有 32 位,然后根据需要分别屏蔽剩余的 16 msb/lsb?或者有没有办法只读取 16 位拳头。
谢谢, 尼科
最佳答案
如果手册说先访问 16 位 LSB,然后访问 16 位 MSB,请按照手册所述进行操作。
例如(小端):
#define REG (*(volatile uint32_t *) 0x1234)
uint16_t val_hi, val_lo;
val_lo = *((volatile uint16_t *) ®);
val_hi = *((volatile uint16_t *) ® + 1);
请注意,编译器有时还会提供 HI 和 LO 标识符来访问 LSB 或 MSB,例如示例中的 REG
:
#define REGL (*(volatile uint16_t *) 0x1234)
#define REGH (*(volatile uint16_t *) 0x1236)
关于c - 从 32 位寄存器读入 16 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9895934/