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.

MSP430 硬件I2C ,时钟SCLK测量。

Other Parts Discussed in Thread: MSP430F5438

大家好。。最近遇到MSP430硬件I2C通信问题,因而想测试一下I2C的SCLK信号。但是官网的I2C程序,在程序编译并写入MSP430F5438开发板之后。再用示波器一端接地一端接对应I2C的UCB0SCLK脚未测试到波形的存在。。因而想请教一下。这种测量方法是否正常呢。??是否有其他测量方法呢。?硬件I2C通信时可以在开发板里面单步运行通信程序么。因为程序单步运行在发送数据的过程中会停留在等待发送区为空,但是全速运行时是不会有任何问题的。。

我测试用的程序如下:

#include "msp430x54x.h"

unsigned char TXData;
unsigned char TXByteCtr;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P11SEL |= BIT0 + BIT1 + BIT2;
  P11DIR |= BIT0 + BIT1 + BIT2;
  P3SEL |= 0x06;                            // Assign I2C pins to USCI_B0
  UCB0CTL1 |= UCSWRST;                      // Enable SW reset
  UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
  UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset
  UCB0BR0 = 12;                             // fSCL = SMCLK/12 = ~100kHz
  UCB0BR1 = 0;
  UCB0I2CSA = 0x48;                         // Slave Address is 048h
  UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
  UCB0IE |= UCTXIE;                         // Enable TX interrupt

  TXData = 0x01;                            // Holds TX data

  while (1)
  {
    TXByteCtr = 1;                          // Load TX byte counter

    while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent
    UCB0CTL1 |= UCTR + UCTXSTT;             // I2C TX, start condition
  
    __bis_SR_register(LPM0_bits + GIE);     // Enter LPM0 w/ interrupts
   __no_operation();                       // Remain in LPM0 until all data
                                            // is TX'd
                                             
    TXData++;                               // Increment data byte
  }
}

//------------------------------------------------------------------------------
// The USCIAB0_ISR is structured such that it can be used to transmit any
// number of bytes by pre-loading TXByteCtr with the byte count.
//------------------------------------------------------------------------------
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
{
  switch(__even_in_range(UCB0IV,12))
  {
  case  0: break;                           // Vector  0: No interrupts
  case  2: break;                           // Vector  2: ALIFG
  case  4: break;                           // Vector  4: NACKIFG
  case  6: break;                           // Vector  6: STTIFG
  case  8: break;                           // Vector  8: STPIFG
  case 10: break;                           // Vector 10: RXIFG
  case 12:                                  // Vector 12: TXIFG 
    if (TXByteCtr)                          // Check TX byte counter
    {
      UCB0TXBUF = TXData;                   // Load TX buffer
      TXByteCtr--;                          // Decrement TX byte counter
    }
    else
    {
      UCB0CTL1 |= UCTXSTP;                  // I2C stop condition
      UCB0IFG &= ~UCTXIFG;                  // Clear USCI_B0 TX int flag
      __bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
    }
    break;
  default: break;
  }
}

  • 请帮忙确认一下几个问题:

    1, 是否有接上拉电阻?

    2, 使用哪几个引脚作为I2C 的SCL SDA?

    可以使用示波器测量数据波形。

    建议安装MSP430ware,使用官方提供的I2C例程修改。

  • 1.  测试I2C的波形时,可以用示波器的探头到CLK或SDA,接地线不可省略。由于示波器的探头等效一个小的电容,所以在测试高速通信时,波形会有点畸变,不用在意。低速通信不存在这个问题。

    2.  由于I2C总线是开漏的总线,如果不接上拉电阻,用示波器是测试不到波形的。

    3.  软件DEBUG的时候,由于发送指令只有一条C代码,所以该代码运行后,会在总线上产生9个CLK信号,这样的DEBUG没多大意义。

    4.  你贴出来的代码就是MSP430F5438的标准例程,代码应该没问题。

  • 示波器选择为触发模式,在发送数据的时候会有CLK信号可以测量。测量方式没有问题。