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 interfacing with TMP102 sensor

Other Parts Discussed in Thread: TMP102

I am trying to use a msp430 to interface with a TMP102 temperature sensor via I2C. 

Currently I am trying to use one of TIs provided examples to get the I2C configured properly.

As of yet I have had no luck getting it to work. The example code I am working with is provided below. 

The only thing that I adjusted is including the proper header file for my device (g2353)

I am not seeing any signals coming off of the SDA or SCL pins. The oscilloscope 

shows no signals at all.

I have been trying all sorts of different things to get this to work for the past few days and still no luck.

Does anyone have any suggestions as to where I should look for a solution? 

//******************************************************************************
// 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 "msp430g2353.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
}
}
  • There are several threads about interfacing the TMP sensors. A forums earch will likely reveal some answers.

  • Thank you Jens-Michael Gross. I saw one post in which you helped someone with their I2C problems and it

    has been somewhat helpful. 

    I got a better O-scope and I am now able to see signals on the lines, however I am not seeing the right things. 

    When I configure the MSP430 as a master receiver and send the slave address it replies with two bytes of data 

    that I am able to capture. However if I configure the master as a master transmitter and send the slave address it 

    does not acknowledge the transmission. I need to send the sensor a byte of data yet I am unable to do so. 

    Any guidance or suggestions would be appreciated. 

    (The code I am using now is essentially the same as what was in my original post. I will upload my current 

    code if requested.)

  • I assume, the first diagram was teh transmit attempt. When teh address has been sent in transmit mode and the you didn't write anythign to TXBUF, the clock is held low in the ACK stage. THat's basically what happens.

    If you take a close look, on the 9th low.going edge of the clock signal (beginning of the ACK bit), you see a small spike on the data line where the master releases the data line. Immediately after, teh slave pulls it low again for its ACK. But sicne hte master is now still waiting for somethign to send, it keeps the clock line low. As soon as you write something to TXBUF, the ACK cycle is ended and the amster begins transmitting the byte. Stoppign again in the ACK clokc cycle of this byte if you didn't fill TXBUF again.
    This is necessary, so you can do a stop/repeated start to end the transmission instead of sending another byte.

    Saince the ACK cycle is not complete, your scope won't draw you the address byte. It's still waiting for the final clock edge. Which never comes since the USCI is waiting for your code to say what's next.

**Attention** This is a public forum