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.

MSP430F5529: MSP430F5529 I2C COMMUNICATION

Part Number: MSP430F5529
Other Parts Discussed in Thread: TMP007

 I want to obtain temperature from tmp007 using i2c communication, Will you guide me through this in ccs coding in c language. I am using a tmp007 temperature sensor with an i2c slave address of 0x40. Will you provide me how to proceed through this process.

  • HI,

    There are some I2C code examples here. It should be helpful.

    https://www.ti.com/lit/zip/slac300

    Best regards,

    Cash Hao

  • #include <msp430.h>

    char Data_In;
    /**
    * main.c
    */
    void main(void)
    {volatile int i;
    WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

    UCB0CTL1 |= UCSWRST;
    UCB0CTL1 |= UCSSEL_3;
    UCB0BRW=10;
    UCB0CTLW0 |=UCMODE_3+UCSYNC;
    UCB0CTL0 |= UCMST;
    UCB0I2CSA = 0x40;
    UCB0TBCNT = 1;
    UCB0CTLW1 |=UCASTP_2;
    P3SEL |= 0x03;
    UCB0CTL1 &=~UCSWRST;
    UCB0IE |= UCTXIE;
    UCB0IE |= UCRXIE;
    __enable_interrupt();
    while(1)
    {
    UCB0CTLW0 |=UCTR;
    UCB0CTLW0 |=UCTXSTT;
    while((UCB0IFG & UCSTPIFG)==0){}
    UCB0IFG &=~UCSTPIFG;
    UCB0CTLW0 &=~UCTR;
    UCB0CTLW0 |=UCTXSTT;
    while((UCB0IFG & UCSTPIFG)==0){}
    UCB0IFG &=~UCSTPIFG;
    }
    }
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    {
    switch(UCB0IV){
    case 0x16:
    Data_In=UCB0RXBUF;
    break;
    case 0x18:
    UCB0TXBUF = 0X01;
    break;
    default:
    break;
    }
    }      

  • I made code like this its showing UCB0TBCNT  is undefined

  • The F5529 has a USCI, not a eUSCI. The USCI doesn't have the auto-stop feature (UCASTP and TBCNT). Be sure you're reading User Guide (SLAU208Q) Chapter 38, not Chapter 41.

    If it's more convenient, the examples are also in Resource Explorer, over here:

    https://dev.ti.com/tirex/explore/node?node=ACt.3NsUP.t3V3gtuC8DhQ__IOGqZri__LATEST

  • hi I have explored the registers in chapter 38 and I did like this 

    #include <msp430.h>

    char Data_In;
    /**
    * main.c
    */
    void main(void)
    {volatile int i;
    WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

    UCB0CTL1 |= UCSWRST;
    UCB0CTL1 |= UCSSEL_3;
    UCB0BRW=10;
    UCB0CTLW0 |=UCMODE_3;
    UCB0CTL0 |= UCMST;
    UCB0I2CSA = 0x40;
    P3SEL |= 0x03;
    UCB0CTL1 &=~UCSWRST;
    UCB0IE |= UCTXIE;
    UCB0IE |= UCRXIE;
    __enable_interrupt();
    while(1)
    {
    UCB0CTLW0 |=UCTR;
    UCB0CTLW0 |=UCTXSTT;
    while((UCB0IFG & UCSTPIFG)==0){}
    UCB0IFG &=~UCSTPIFG;
    UCB0CTLW0 &=~UCTR;
    UCB0CTLW0 |=UCTXSTT;
    while((UCB0IFG & UCSTPIFG)==0){}
    UCB0IFG &=~UCSTPIFG;
    }
    }
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    {
    switch(UCB0IV){
    case 0x16:
    Data_In=UCB0RXBUF;
    break;
    case 0x18:
    UCB0TXBUF = 0X01;
    break;
    default:
    break;
    }
    }

  • but I still not able to view output in oscilloscope

  • I want to read data from slave address 40 and register address 0x1h

    still I didn't getting any o/p in oscilloscope is there any particular register to view data directly . 

  • #include <msp430.h>

    char Data_In;
    /**
    * main.c
    */
    void main(void)
    {volatile int i;
    WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer

    UCB0CTL1 |= UCSWRST;
    UCB0CTL1 |= UCSSEL_2;
    UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
    UCB0BR1 = 0;
    UCB0CTLW0 |=UCMODE_3+ UCSYNC;
    UCB0CTL0 |= UCMST;
    UCB0I2CSA = 0x40;
    P3SEL |= 0x03;
    UCB0CTL1 &=~UCSWRST;
    UCB0IE |= UCTXIE;
    UCB0IE |= UCRXIE;
    __enable_interrupt();
    while(1)
    {
    UCB0CTLW0 |=UCTR;
    UCB0CTLW0 |=UCTXSTT;
    while((UCB0IFG & UCSTPIFG)==0){}
    UCB0IFG &=~UCSTPIFG;
    UCB0CTLW0 &=~UCTR;
    UCB0CTLW0 |=UCTXSTT;
    while((UCB0IFG & UCSTPIFG)==0){}
    UCB0IFG &=~UCSTPIFG;
    }
    }
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    {
    switch(UCB0IV){
    case 0x02:
    Data_In=UCB0RXBUF;
    break;
    case 0x04:
    UCB0TXBUF = 0X01;
    break;
    default:
    break;
    }
    }

  • o/p is getting like this even clock not getting properly

  • 1) The UCB0IV values for RXIFG/TXIFG are 0x0A/0x0C [Ref User Guide (SLAU208Q) Table 38-14].

    2) I'm not quite sure what the scope trace is showing. If you're not getting a clock, check your pullups.

    3) TI publishes a USCI troubleshooting guide (SLAA734A) which is probably worth a look:

    https://www.ti.com/lit/an/slaa734a/slaa734a.pdf

    4) I encourage you to at least read over the I2C examples mentioned above. The sequence you've chosen may work, but I haven't tried it.

  • #include <msp430.h>
    char Data_In=0;
    void main(void)
    {volatile int i;
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT // P1.0 output
    P3SEL |= 0x03; // Assign I2C pins to USCI_B0
    UCB0CTL1 |= UCSWRST; // Enable SW reset
    UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
    UCB0CTL1 |= UCSSEL_2; // Use SMCLK
    UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
    UCB0BR1 = 0;
    UCB0I2CSA = 0x40; // Slave Address is 048h
    UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
    UCB0IE |= UCRXIE;
    UCB0IE |= UCTXIE;
    __enable_interrupt();
    while(1)
    {
    UCB0CTL1 |=UCTR;
    UCB0CTL1 |=UCTXSTT;
    while((UCB0IFG & UCSTPIFG)==0){}
    UCB0IFG &=~UCSTPIFG;
    UCB0CTL1 &=~UCTR;
    UCB0CTL1 |=UCTXSTT;
    while((UCB0IFG & UCSTPIFG)==0){}
    UCB0IFG &=~UCSTPIFG;
    }
    }
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    {
    switch(UCB0IV){
    case 0x0A:
    Data_In=UCB0RXBUF;
    break;
    case 0x0C:
    UCB0TXBUF = 0X03;
    break;
    default:
    break;
    }
    }

    This is the code I have used meanwhile I changed the same but didn't  got the true one which is required.

  • Hi,

    What is the D0, D1 and Bus 1 in your figure? And have you connected to an I2C slave when testing your code?

    Best regards,

    Cash Hao

  • yes I have shared another forum cash that's my present status could you look into it

    e2e.ti.com/.../3830782

**Attention** This is a public forum