TI 的I2C代码,不出结果,有个点看不懂,求指教

2019-03-24 12:17发布

代码如下,不知道为什么开的是RX中断,却用TX中断向量接受,我下到片子里,发现连时钟都没有输出,我用的G2553的LaunchPad
  1. //******************************************************************************
  2. //  MSP430G2xx3 Demo - USCI_B0 I2C Master RX multiple bytes from MSP430 Slave
  3. //
  4. //  Description: This demo connects two MSP430's via the I2C bus. The slave
  5. //  transmits to the master. This is the master code. It continuously
  6. //  receives an array of data and demonstrates how to implement an I2C
  7. //  master receiver receiving multiple bytes using the USCI_B0 TX interrupt.
  8. //  ACLK = n/a, MCLK = SMCLK = BRCLK = default DCO = ~1.2MHz
  9. //
  10. //  *** to be used with "msp430g2xx3_uscib0_i2c_11.c" ***
  11. //
  12. //                                /|  /|
  13. //               MSP430G2xx3      10k  10k     MSP430G2xx3
  14. //                   slave         |    |        master
  15. //             -----------------   |    |  -----------------
  16. //           -|XIN  P3.1/UCB0SDA|<-|---+->|P3.1/UCB0SDA  XIN|-
  17. //            |                 |  |      |                 |
  18. //           -|XOUT             |  |      |             XOUT|-
  19. //            |     P3.2/UCB0SCL|<-+----->|P3.2/UCB0SCL     |
  20. //            |                 |         |                 |
  21. //
  22. //  D. Dang
  23. //  Texas Instruments Inc.
  24. //  February 2011
  25. //  Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
  26. //******************************************************************************
  27. #include

  28. unsigned char *PRxData;                     // Pointer to RX data
  29. unsigned char RXByteCtr;
  30. volatile unsigned char RxBuffer[128];       // Allocate 128 byte of RAM

  31. int main(void)
  32. {
  33.   WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  34.   P1SEL |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
  35.   P1SEL2|= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
  36.   UCB0CTL1 |= UCSWRST;                      // Enable SW reset
  37.   UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
  38.   UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset
  39.   UCB0BR0 = 12;                             // fSCL = SMCLK/12 = ~100kHz
  40.   UCB0BR1 = 0;
  41.   UCB0I2CSA = 0x02;                         // Slave Address is 048h
  42.   UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
  43.   IE2 |= UCB0RXIE;                          // Enable RX interrupt

  44.   while (1)
  45.   {
  46.     PRxData = (unsigned char *)RxBuffer;    // Start of RX buffer
  47.     RXByteCtr = 5;                          // Load RX byte counter
  48.     while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent
  49.     UCB0CTL1 |= UCTXSTT;                    // I2C start condition
  50.     __bis_SR_register(CPUOFF + GIE);        // Enter LPM0 w/ interrupts
  51.                                             // Remain in LPM0 until all data
  52.                                             // is RX'd
  53.     __no_operation();                       // Set breakpoint >>here<< and
  54.   }                                         // read out the RxBuffer buffer
  55. }

  56. //-------------------------------------------------------------------------------
  57. // The USCI_B0 data ISR is used to move received data from the I2C slave
  58. // to the MSP430 memory. It is structured such that it can be used to receive
  59. // any 2+ number of bytes by pre-loading RXByteCtr with the byte count.
  60. //-------------------------------------------------------------------------------
  61. #pragma vector = USCIAB0TX_VECTOR
  62. __interrupt void USCIAB0TX_ISR(void)
  63. {
  64.   RXByteCtr--;                              // Decrement RX byte counter
  65.   if (RXByteCtr)
  66.   {
  67.     *PRxData++ = UCB0RXBUF;                 // Move RX data to address PRxData
  68.     if (RXByteCtr == 1)                     // Only one byte left?
  69.       UCB0CTL1 |= UCTXSTP;                  // Generate I2C stop condition
  70.   }
  71.   else
  72.   {
  73.     *PRxData = UCB0RXBUF;                   // Move final RX data to PRxData
  74.     __bic_SR_register_on_exit(CPUOFF);      // Exit LPM0
  75.   }
  76. }

复制代码 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
6条回答
zhaojun_xf
2019-03-24 15:30
< 顶,不行就改模拟,比较通用。。。。。。。

一周热门 更多>

相关问题

    相关文章