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/MSP430G2553:I2C 通信存在问题

Guru**** 2542190 points
Other Parts Discussed in Thread: MSP430G2553

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/567203/ccs-msp430g2553-problem-with-i2c-communication

器件型号:MSP430G2553

工具/软件:Code Composer Studio

大家好、

我正在努力将 BMP180传感器连接到 msp430g2553。 我已经在 MSP430中完成了 I2C 与 BMP180通信的配置部分。 但通信并未建立。 它将进入 while 循环。 我随附了我的代码。

空 BMP180GetCalVals (tBMP180Cals * calInst)

 静态常量 uint8_t bmpCalRegs[11]={BMP180_REG_CAL_AC1、BMP180_REG_CAL_AC2、BMP180_REG_CAL_AC3、BMP180_REG_CAL_AC4、BMP180_REG_CAL_AC5、                                                BMP180_REG_CAL_AC6、BMP180_REG_CAL_B1、BMP180_REG_CAL_B2、BMP180_REG_CAL_MB、BMP180_REG_CAL_MC、  BMP180_REG_CAL_MD};
 
uint8_t bmpCalBytes[22];
 
uint8_t bmpCalCount=0;


 UCB0CTL1 |= UCSWRST;

 UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;

 UCB0CTL1 = UCSSEL_2;

 UCB0BR0 = 0x12;  // 100kHz
 
       UCB0BR1 = 0x00;
 
       UCB0I2CSA = BMP180_I2C_ADDRESS;
 
       UCB0CTL1 &=~UCSWRST;


 while (bmpCalCount < 11)
       {
  
               while (UCB0CTL1 & UCTXSTP);

  UCB0CTL1 |= UCTR + UCTXSTT;

  while (UCB0CTL1 & UCTXSTT);//程序在这里执行。


  UCB0TXBUF = bmpCalRegs[bmpCalCount];

  while (!(IFG2 & UCB0TXIFG));

  UCB0CTL1 &=~UCTR;
 
        UCB0CTL1 |= UCTXSTT;

  while (UCB0CTL1 & UCTXSTT);

  bmpCalBytes[2*bmpCalCount]= UCB0RXBUF;

  while (!(IFG2 & UCB0RXIFG));
 
        UCB0CTL1 |= UCTXSTT;
  
               while (UCB0CTL1 & UCTXSTT);
 
        bmpCalBytes[2*bmpCalCount+1]= UCB0RXBUF;
 
        while (!(IFG2 & UCB0RXIFG));
  
               UCB0CTL1 |= UCTXSTP;

 
        BmpCalCount++;
 
        UCB0CTL1 |= UCTR;

 }

 
       calInst->AC1 =(Int16_t)((bmpCalBytes[0]<<8)| bmpCalBytes[1]);
 
       calInst->AC2 =(Int16_t)((bmpCalBytes[2]<<8)| bmpCalBytes[3]);

 calInst->ac3 =(int16_t)((bmpCalBytes[4]<<8)| bmpCalBytes[5]);
 
       calInst->AC4 =(uint16_t)((bmpCalBytes[6]<<8)| bmpCalBytes[7]);

 calInst->AC5 =(uint16_t)((bmpCalBytes[8]<<8)| bmpCalBytes[9]);
 
       calInst->AC6 =(uint16_t)((bmpCalBytes[10]<<8)| bmpCalBytes[11]);
 
       calInst->b1 = (int16_t)((bmpCalBytes[12]<<8)|bmpCalBytes[13]);
 
       calInst->b2= (Int16_t)((bmpCalBytes[14]<<8)|bmpCalBytes[15]);
 
       calInst->MB = (int16_t)((bmpCalBytes[16]<<8)|bmpCalBytes[17]);
 
       calInst->MC = (int16_t)((bmpCalBytes[18]<<8)|bmpCalBytes[19]);
 
       calInst->MD = (int16_t)((bmpCalBytes[20]<<8)| bmpCalBytes[21]);

请仔细检查 我编写的 I2C 配置、如果 出现问题、请通过更正来帮助我。 我只想在 MSP430和传感器之间建立连接。 我在 SCL 和 SDA 线路之间使用了10k 上拉电阻器。

谢谢、此致、

Subash

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

    在开始序列后、在 while 环路中滞留的一个常见原因是未提供正确的从器件地址、或者您从从器件接收到 NACK。 NACK 可能由硬件连接问题引起。

    此处的最佳做法是使用逻辑分析仪来查看 SCL 和 SDA 线路、并查看线路上实际发生的情况。 如果您没有逻辑分析仪、使用示波器和截屏也会很有帮助。 完成此操作后、您能否发布屏幕截图供我查看?

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

    您是否仍然需要有关此问题的帮助、或者是否取得了您想要分享的任何进展?

    此致、
    Caleb Overbay