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.

MSP430F2618 I2C to TMP112 Help

Other Parts Discussed in Thread: TMP112, MSP430F2618

Hey guys and gals,

 I have been searching and reading all posts about MSP430 and TMP112  I2C setup. I for the life of me cannot read any information from the TMP112. The TMP112 ADD0 pin is connected to ground so therefore, I am addressing it as 0x48. I've been oscoping this and I am getting a clock and data on the SCL and SDA lines respectfully. Below is my code, and I removed a lot from it that I was using to troubleshoot it.

When I am debugging I am only getting 0xFF from the RXBUF. Also, are my sequence and notes accurate? What am I missing from code? Please help. Thank you.

#include <msp430x26x.h>
#include <stdlib.h>                               //Processor specific definitions
#include <stdio.h>


unsigned char SADDR = 0x48;        //Slave address for TMP112 WRITE TO 0b01001000
unsigned char RADDR = 0x00;       //Slave register address for TMP112

unsigned char temp= 0x00;                   //assign temperature variable


void I2C_Setup_B1();                        // Define Initialization of Systems
void init_setup();
void readI2C();
void init_clock();

int main( void )
{
WDTCTL = WDTPW + WDTHOLD;               // Stop WDT
init_clock();
init_setup();

while(1)
{
readI2C();
}
}

void init_clock()
{
// Turning on XTAL2
BCSCTL3 |= XT2S1;                  // Allow external 3-16 MHz crystal
BCSCTL1 &= ~XT2OFF;            // Turn on XT2

// SMCLK (from XTAL2) 
BCSCTL2 |= SELS;                    // Source SMCLK from XT2 = 16MHz
BCSCTL2 |= DIVS0;                   // Divide SMCLK by 2 = 8MHz
}


void init_setup()
{
P5SEL |= 0x06;                            //Assign P5.1,2 as UCB1_SDA,SCL
I2C_Setup_B1();                          //Call Function Setup UCBI for I2C
}

void I2C_Setup_B1()
{
UCB1CTL1 |= UCSWRST;                                                       // Enable SoftWare reset
UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC;              // Mode: Master, I2C, synchronous
UCB1CTL1 = UCSSEL_2 + UCSWRST;                               // Use SMCLK, keep SW reset
UCB1BR0 = 80; // fSCL = SMCLK/80 = ~100kHz
UCB1BR1 = 0;

UCB1CSA = SADDR;                                                               //Set Slave address 0x48
UCB1CTL1 &= ~UCSWRST;                                                   // Clear SW reset, resume operation
}

void readI2C()
{
UCB1CTL0 &= ~UCSLA10;                      // Enable 7 bit slave address option
UCB1CTL1 |= UCTR;                                // Master is a transmitter
UCB1CTL1 |= UCTXSTT;                         // Staart : TXIFG flag is raised
unsigned char hold = 0x00;

while (hold == 0x00){
hold = UC1IFG & UCB1TXIFG;                //wait until slave address is sent completely
}
UCB1TXBUF = RADDR;                            // input register addr into TXBUF, TXIFG flag cleared
hold = 0x00;                                                  //clear hold variable for next wait cycle

//TMP112 is now setup with it being addressed and its register when temp data is now address
//Now starting the Master Receiver mode where the TMP112 will be outputting temperature data to MSP430
//Master Receiver Mode

UCB1CTL1 &= ~UCTR;                                    // Master is a receiver
UCB1CTL1 |= UCTXSTT;                                 // Repeated Staart

while (hold == 0x00){
hold = (UC1IFG & UCB1RXIFG);                      // Wait for RX Interrupt flag
}
temp = UCB1RXBUF;
hold = 0x00;

while (hold == 0x00){
hold = (UC1IFG & UCB1RXIFG);                       // Wait for RX Interrupt flag
}
temp = UCB1RXBUF;
hold = 0x00;
UCB1CTL1 |= UCTXSTP;                                   // I2C stop condition
}

 

  • **TYPO**
    UCB1I2CSA = SADDR;
  • Hey James,

    What are the values of your pull-up resistors?  They should be 5 kOhm according to the TMP112 datasheet.  A few notes:

    1. BCSCTL3 should be set to XT2S2 for 16 MHz operation.

    2. You should implement a OSCFault flag check, like below:

      do
      {
        IFG1 &= ~OFIFG;                         // Clear OSCFault flag
        for (i = 0xFF; i > 0; i--);             // Time for flag to set
      }
      while (IFG1 & OFIFG);                     // OSCFault flag still set?

    3. Ensure that a stop condition got sent (while (UCB0CTL1 & UCTXSTP);) before sending a start condition.  Same with sending stop conditions.

    4. You should use your oscilloscope to ensure that the Timing Diagram in Figures 11-13 are matched by your MSP430 code.  It appears to me that you are only sending a slave address followed by one byte (pointer register) without sending any data bytes.  You then transition to receiver mode before sending the stop condition.  This is most likely why you are only receiving 0xFF responses.  Please review the MSP430F2618 I2C code examples for more information regarding how to properly communicate through I2C.

    Regards, Ryan

  • Hello James,

    Did my suggestions help solve your I2C problems?

    Regards,
    Ryan

**Attention** This is a public forum