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.

[参考译文] CCS/MSP430F249:我想在 I2C 通信中读取两个字节

Guru**** 2539500 points


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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/899535/ccs-msp430f249-i-would-like-to-read-two-bytes-in-i2c-communcation

器件型号:MSP430F249

工具/软件:Code Composer Studio

我尝试从 PCT2075获取温度

https://www.nxp.com/docs/en/data-sheet/PCT2075.pdf

我编写了一个代码、用于读取 I2C 中的多个字节。

但是、它看起来像是从寄存器地址读取的同一字节而不是两个字节。

我不知道该代码有什么问题。

void i2c_read_multi(uint8_t SLV_addr、uint8_t reg_addr、uint8_t l、uint8_t *arr)
{

uint8_t i;

while (UCB0STAT 和 UCBBUSY);
UCB0I2CSA = SLV_addr; //设置从器件地址
UCB0CTL1 |= UCTR | UCTXSTT; //发送器模式和启动条件。
while (UCB0CTL1 & UCTXSTT);
UCB0TXBUF = REG_addr;
while (IFG2 & UCB0TXIFG = 0);
UCB0CTL1 &=~UCTR; //接收器模式
UCB0CTL1 |= UCTXSTT; //起始条件
while (UCB0CTL1 & UCTXSTT); //确保已清除启动

对于(i = 0;i < l;i++){
if (i = l - 1){
UCB0CTL1 |= UCTXSTP; //停止条件
}
while (!(IFG2 & UCB0RXIFG));
ARR[i]= UCB0RXBUF;
}
while (UCB0CTL1 & UCTXSTP);
} 

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

    This looks like a typo. Did you mean

    >       while (!(IFG2 & UCB0RXIFG));

     

     

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

    抱歉。 有人进行了分型。

    是的

    while (!(IFG2 & UCB0RXIFG));

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

    这与您描述的症状不符、但:  

    >     while(IFG2 & UCB0TXIFG == 0);

    This doesn't do what you want. Try:

    >     while((IFG2 & UCB0TXIFG) == 0);

    Also, this should precede, not follow, writing to TXBUF.