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.

[参考译文] MSP430F2416:使用 SPI 读取24位寄存器

Guru**** 2546020 points
Other Parts Discussed in Thread: AFE4490

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/757767/msp430f2416-reading-a-24-bit-register-by-using-spi

器件型号:MSP430F2416
主题中讨论的其他器件:AFE4490

大家好、

我已经尝试 通过 SPI 读取 AFE4490的24位寄存器、如何有效地完成此操作、我已经尝试了以下方法、请帮助解决此问题。

无符号长整型 AFE4490_Reg_Read (无符号字符 REG_ADDRESS)

P1OUT &=~ BIT4;

while (!(UC1IFG & UCA1TXIFG));
UCA1TXBUF = REG_ADDRESS;
while (!(UC1IFG & UCA1RXIFG));
SPI_Rx_buff1= UCA1RXBUF;

while (!(UC1IFG & UCA1TXIFG));
UCA1TXBUF = 0x00;
while (!(UC1IFG & UCA1RXIFG));
SPI_Rx_buff2= UCA1RXBUF;

while (!(UC1IFG & UCA1TXIFG));
UCA1TXBUF = 0x00;
while (!(UC1IFG & UCA1RXIFG));
SPI_Rx_buff3= UCA1RXBUF;

while (!(UC1IFG & UCA1TXIFG));
UCA1TXBUF = 0x00;
while (!(UC1IFG & UCA1RXIFG));
SPI_Rx_buff4= UCA1RXBUF;

P1OUT |= BIT4;

retValue =(SPI_Rx_buff4|(SPI_Rx_buff3<<8)|(SPI_Rx_buff2<<16));

返回 retValue;

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    > retValue =(SPI_Rx_buff4|(SPI_Rx_buff3<<8)|(SPI_Rx_buff2<<16));

    我的第一个猜测是 SPI_Rx_buffX 被声明为 uint8_t (或无符号字符)、因此它们不能承受移位。 尝试:

    > retValue =((unsigned long) SPI_Rx_buff4|(unsigned long) SPI_Rx_buff3<<8)|((unsigned long) SPI_Rx_buff2<<16);

    (也可以使用 uint32_t 而不是"unsigned long"(如果已有)。