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.

Problems Regarding TMP100

Other Parts Discussed in Thread: TMP100

Hello everyone,

I have an MSP430 Launchpad with the 2553 microcontroller installed and all I am trying to do is to get the sample code given for TMP100 to work. I have uploaded the sample code which was provided by TI to demonstrate the launchpad's I2C capabilities. I have made no changes to the sample code and I have directly programmed it into my microcontroller. I have connected the TMP100 as shown in the diagram in the comments section of the code. The sample code available on the Launchpad Wiki makes the MSP430 talk to TMP100 via I2C to retrieve the temperature and turn on the red LED if the temperature is above 28C.

The SCL and SDA pins are both pulled up by 10K resistors and ADD0 and ADD1 are connected to VCC. As you all know, the program turns on the red LED when the temperature is above 28 C. The problem is that the red LED is always on whether the temperature is above or below 28 C. I have also tried grounding the ADD0 and ADD1 pins to see whether that made a change but it did nothing. I also tried putting a 0.1 uF capacitor connected to VCC and GND but no good. Would you guys be able to help me out with this and tell me what I am doing wrong?

Thank you very much

Anil

//******************************************************************************
//  MSP430G2xx3 Demo - USCI_B0 I2C Master to TMP100, Set P1.0 if Temp > 28C
//
//  Description: I2C interface to TMP100 temperature sensor in 9-bit mode.
//  Timer_A CCR0 interrupt is used to wake up and read the two bytes of
//  the TMP100 temperature register every 62ms. If the temperature is greater
//  than 28C, P1.0 is set, else reset. CPU is operated in LPM0. I2C speed
//  is ~100kHz.
//  ACLK = n/a, MCLK = SMCLK = TACLK = BRCLK = default DCO = ~1.2MHz
//
//         /|\           /|\ /|\
//          |   TMP100   10k 10k     MSP430G2xx3
//          |   -------   |   |   -------------------
//          +--|Vcc SDA|<-|---+->|P1.7/UCB0SDA    XIN|-
//          |  |       |  |      |                   |
//          +--|A1,A0  |  |      |               XOUT|-
//             |       |  |      |                   |
//          +--|Vss SCL|<-+------|P1.6/UCB0SCL   P1.0|---> LED
//         \|/  -------          |                   |
//
//  D. Dang
//  Texas Instruments Inc.
//  February 2011
//   Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************
#include "msp430g2553.h"

unsigned int RxByteCtr;
unsigned int RxWord;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P1DIR |= BIT0;                            // P1.0 output
  P1SEL |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
  P1SEL2|= BIT6 + BIT7;                     // 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 = 0x4e;                         // Set slave address
  UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
  IE2 |= UCB0RXIE;                          // Enable RX interrupt
  TACTL = TASSEL_2 + MC_2;                  // SMCLK, contmode

  while (1)
  {
    RxByteCtr = 2;                          // Load RX byte counter
    UCB0CTL1 |= UCTXSTT;                    // I2C start condition
    __bis_SR_register(CPUOFF + GIE);        // Enter LPM0, enable interrupts
                                            // Remain in LPM0 until all data
                                            // is RX'd

    if (RxWord < 0x1d00)                    // >28C?
      P1OUT &= ~0x01;                       // No, P1.0 = 0
    else
      P1OUT |= 0x01;                        // Yes, P1.0 = 1

    __disable_interrupt();
    TACCTL0 |= CCIE;                        // TACCR0 interrupt enabled
    __bis_SR_register(CPUOFF + GIE);        // Enter LPM0, enable interrupts
                                            // Remain in LPM0 until TACCR0
                                            // interrupt occurs
    TACCTL0 &= ~CCIE;                       // TACCR0 interrupt disabled
  }
}

#pragma vector = TIMER0_A0_VECTOR
__interrupt void TA0_ISR(void)
{
  __bic_SR_register_on_exit(CPUOFF);        // Exit LPM0
}

// The USCIAB0TX_ISR is structured such that it can be used to receive any
// 2+ number of bytes by pre-loading RxByteCtr with the byte count.
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
  RxByteCtr--;                              // Decrement RX byte counter

  if (RxByteCtr)
  {
    RxWord = (unsigned int)UCB0RXBUF << 8;  // Get received byte
    if (RxByteCtr == 1)                     // Only one byte left?
      UCB0CTL1 |= UCTXSTP;                  // Generate I2C stop condition
  }
  else
  {
    RxWord |= UCB0RXBUF;                    // Get final received byte,
                                            // Combine MSB and LSB
    __bic_SR_register_on_exit(CPUOFF);      // Exit LPM0
  }
}

  • Did you manage to solve your problem since I have the same problem as yours. I hope you can provide some help.

    Regards,

    Amir

  • No, I kind of gave up on it and moved on. I was hoping to get some help on this on E2E. I will post here solution if I ever figure it out though.

  • Hello Again I fixed the issue with the temp and getting correct result: Try to use this code and see whether it works or not, it worked for me now.

    #include "cc430x613x.h"
    #define RED_LED BIT6
    #define GRN_LED BIT0
    unsigned int RxByteCtr;
    unsigned int RxWord;
    //volatile unsigned char RxBuffer[1]; // Allocate 128 byte of RAM
    void main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT

    P1OUT = 0;
    P3OUT = 0;
    P1DIR |= GRN_LED;
    P3DIR |= RED_LED;

    P1SEL |= BIT2 + BIT3; // 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 = 0x4e; // Set slave address
    UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
    UCB0IE |= UCRXIE; // Enable RX interrupt
    TA1CTL = TASSEL_2 + MC_2; // ACLK, upmode, clear TAR

    while (1)
    {
    RxByteCtr = 2; // Load RX byte counter
    UCB0CTL1 |= UCTXSTT; // I2C start condition
    __bis_SR_register(CPUOFF + GIE); // Enter LPM0, enable interrupts
    // Remain in LPM0 until all data
    // is RX'd
    if (RxWord < 28) // >28C?
    P1OUT &= ~0x01; // No, P1.0 = 0
    else
    P1OUT |= 0x01; // Yes, P1.0 = 1
    __disable_interrupt();

    TA1CCTL0 = CCIE;
    __bis_SR_register(CPUOFF + GIE); // Enter LPM0, enable interrupts TA1CCTL0 &= ~CCIE; // Remain in LPM0 until TACCR0
    // interrupt occurs
    TA1CCTL0&= ~CCIE;
    }
    }
    // The USCIAB0TX_ISR is structured such that it can be used to receive any
    // 2+ number of bytes by pre-loading RxByteCtr with the byte count.
    #pragma vector = USCI_B0_VECTOR
    __interrupt void USCI_B0_ISR(void)
    {
    RxByteCtr--; // Decrement RX byte counter
    if (RxByteCtr)
    {
    RxWord = (unsigned int)UCB0RXBUF ; // Get received byte
    if (RxByteCtr == 1) // Only one byte left?
    UCB0CTL1 |= UCTXSTP; // Generate I2C stop condition
    }
    else
    {
    RxWord |= UCB0RXBUF; // Get final received byte,
    // Combine MSB and LSB
    __bic_SR_register_on_exit(CPUOFF); // Exit LPM0
    }
    }
    // Timer A0 interrupt service routine
    #pragma vector=TIMER1_A0_VECTOR
    __interrupt void TIMER1_A0_ISR(void)
    {
    __bic_SR_register_on_exit(CPUOFF); // Exit LPM0
    }
    
    

    Good Luck in that If you need any explanation just ask ... 

    Regards..

**Attention** This is a public forum